Single JavaScript file Actors are being deprecated

We will automatically convert single-file Actors to multi-file and keep them working. If you are using Apify API to update the code of your single-file actors or create new ones, then you will have to update your API integration following the instructions below.

Content

We've decided to say goodbye to single-file JavaScript Actors, but don't worry, we will automatically convert them to multi-file.

TL;DR: We will automatically convert single-file Actors to multi-file and keep them working. If you are using the Apify API to update the code of your single-file Actors or create new ones, then you will have to update your API integration by following the instructions below.

Why deprecate single-file JavaScript Actors?

Because they brought only pain and frustration to developers 😫

The main problem with single-file Actors is the lack of package.json and package-lock.json files so that the versions of your dependencies can (and do) vary in-between builds.

Single-file Actors were built in such a way that they used:

  • apify and apify-client packages in the version baked into the base docker image
  • all other packages required in source code in the latest version

When you rebuild the Actor and a new version of the package you were using contained some backward-compatibility breaks, your Actor would break even if you did not change a single line in the source code.

There was no way around this.

Say goodbye to single-file JavaScript actors and hello to multi-file actors
Say goodbye to single-file JavaScript Actors and hello to multi-file Actors

What will happen to existing single-file Actors?

They will be converted to their multi-file equivalents. The multi-file version will contain the following files:

  • Dockerfile - based on the original base docker image
  • main.js - the original source code
  • package.json - containing apify and apify-client in latest version (or a specific version if you use a base docker image that is deprecated) and all other required packages in latest version.
Source of actor before and after conversion to multi-file
Source of Actor before and after conversion to multi-file

This means that if your Actor breaks due to some package version incompatibility, you can now pin its version in package.json.

What should I do with my existing Actors?

You can convert the existing single-file Actors manually in Apify Console, in the source tab of your Actor. The conversion does not influence existing builds in any way, the converted files are only used for new builds.

You will see a message in Apify Console warning you to convert your single-file actors
You will see a message in Apify Console warning you to convert your single-file actors

We'll convert all the remaining Actors by June 1, 2022.

Monetize your code · Apify
Publish your code on the Apify platform, attract people who need your solution, and get paid!

See how you can make money by making Actors for web scraping and automation

What should I do when using API to create or update single-file Actors?

Switch to multi-file Actors before June 1, 2022. After that, it will no longer be possible to create single-file actors.

Instead of a single-file version with sourceType set to SOURCE_CODE, some sourceCode and baseDockerImage, use version with sourceType set to SOURCE_FILES and add array sourceFiles, which should contain Dockerfile, package.json (if needed) and main.js described above.

You can either create those files on your own or convert existing single-file Actors manually in UI, read the converted version via API and then use sourceFiles when creating similar new Actors - just change the content of main.js (and package.json if you need to add some packages).

Minimal example

When you create single-file Actors via API, you make a POST request to https://api.apify.com/v2/acts with payload such as this:

{
  "name": "my-single-file-actor-001",
  "versions": [
    {
      "versionNumber": "0.0",
      "sourceType": "SOURCE_CODE",
      "buildTag": "latest",
      "baseDockerImage": "apify/actor-node",
      "sourceCode": "console.log('Hello world!');"
    }
  ]
}

For multi-file Actors, you have to list all the files that make up your Actor in the payload:

{
  "name": "my-multi-file-actor-001",
  "versions": [
    {
      "versionNumber": "0.0",
      "sourceType": "SOURCE_FILES",
      "buildTag": "latest",
      "sourceFiles": [
        {
          "name": "Dockerfile",
          "format": "TEXT",
          "content": "FROM apify/actor-node\nCOPY . .\n"
        },
        {
          "name": "main.js",
          "format": "TEXT",
          "content": "console.log('Hello world!');"
        }
      ]
    }
  ]
}

If you need to install some additional packages, don't forget to add package.json and RUN npm install in the Dockerfile.

See the version object documentation for details.

If you have any problems or questions about the conversion, contact our support on chat in Apify Console.

Josef Válek
Josef Válek
Full-stack developer @apify.

Get started now

Step up your web scraping and automation