Environment
Summary
When Claude Code auto-runs the apify-trend-analysis skill on Windows, the skill’s reference runner script reference/scripts/run_actor.js crashes immediately with an ESM/CommonJS module loading error. The script uses ESM syntax (import ... from ...), but Node loads it as CommonJS (likely because it is a .js file without a "type": "module" package scope), resulting in:
SyntaxError: Cannot use import statement outside a module
Additionally, the default invocation uses node --env-file=.env (relative path). In the Claude Code execution context, the working directory (cwd) is not obvious/consistent, so .env is frequently not found, which leads to “token not found” / auth failures unless the user manually rewrites the command to an absolute --env-file=... path.
Steps to Reproduce
- On Windows (native), install Node.js 22.x.
- In Claude Code, install/use the Apify Agent Skills and trigger the
apify-trend-analysis skill so Claude Code executes it automatically.
- Claude Code runs a command similar to (path may vary, but structure is the same):
node --env-file=.env "C:/Users/<user>/.claude/plugins/cache/apify-agent-skills/apify-trend-analysis/1.0.1/reference/scripts/run_actor.js" --actor "apify/..."
- (Optional) If you attempt to fix the token loading by using an absolute env file path:
node --env-file=C:/Users/<user>/.claude/.env "C:/Users/<user>/.claude/plugins/cache/apify-agent-skills/apify-trend-analysis/1.0.1/reference/scripts/run_actor.js" --actor "apify/..."
- Observe the failure.
Actual Result
The process exits with code 1 and logs:
(node:8736) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
C:\Users\<user>\.claude\plugins\cache\apify-agent-skills\apify-trend-analysis\1.0.1\reference\scripts\run_actor.js:13
import { parseArgs } from 'node:util';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (node:internal/modules/cjs/loader:1378:20)
at Module._compile (node:internal/modules/cjs/loader:1428:41)
...
Separately, with the default --env-file=.env, .env may not be found depending on the cwd, causing token/auth issues before even reaching actor execution.
Expected Result
- The
apify-trend-analysis skill should run successfully on Windows with modern Node (e.g., Node 20+ / 22), without requiring manual patching in a plugin cache directory.
- Token loading should be reliable (either document exactly where
.env must be placed, use a stable default location such as ~/.claude/.env, or avoid a cwd-dependent relative --env-file=.env).
Suspected Root Cause
reference/scripts/run_actor.js is written as an ESM module, but it is being executed in a CommonJS context:
- No
package.json with "type": "module" in the script’s package scope, and/or
- The published/plugin layout causes Node’s module type resolution to treat it as CommonJS.
- The use of
--env-file=.env is cwd-dependent; Claude Code’s execution cwd may differ from the user’s project directory.
Workarounds (Temporary)
- Add a
package.json containing:
into the directory:
...\reference\scripts\
so Node treats run_actor.js as ESM. (This is a cache directory, so updates may overwrite it.)
- Or rename the script to
.mjs (also not ideal for a cached/published artifact).
- For token loading, pass an absolute path to
--env-file=... instead of relying on .env in cwd.
Suggested Fix
Any of the following would address the ESM crash:
- Ship a
package.json with "type": "module" in the appropriate scope for reference/scripts/run_actor.js.
- Rename
run_actor.js to run_actor.mjs and update the invocation accordingly.
- Rewrite the runner as CommonJS (
require) to avoid ESM scope issues (less preferred).
And for token loading reliability:
- Avoid cwd-relative
--env-file=.env by default (or clearly document required cwd / expected .env location), or
- Default to
~/.claude/.env on all platforms.
Reference
Environment
apify/agent-skillsREADME.mdhttps://github.com/apify/agent-skills/blob/main/README.mdSummary
When Claude Code auto-runs the
apify-trend-analysisskill on Windows, the skill’s reference runner scriptreference/scripts/run_actor.jscrashes immediately with an ESM/CommonJS module loading error. The script uses ESM syntax (import ... from ...), but Node loads it as CommonJS (likely because it is a.jsfile without a"type": "module"package scope), resulting in:SyntaxError: Cannot use import statement outside a moduleAdditionally, the default invocation uses
node --env-file=.env(relative path). In the Claude Code execution context, the working directory (cwd) is not obvious/consistent, so.envis frequently not found, which leads to “token not found” / auth failures unless the user manually rewrites the command to an absolute--env-file=...path.Steps to Reproduce
apify-trend-analysisskill so Claude Code executes it automatically.Actual Result
The process exits with code 1 and logs:
Separately, with the default
--env-file=.env,.envmay not be found depending on the cwd, causing token/auth issues before even reaching actor execution.Expected Result
apify-trend-analysisskill should run successfully on Windows with modern Node (e.g., Node 20+ / 22), without requiring manual patching in a plugin cache directory..envmust be placed, use a stable default location such as~/.claude/.env, or avoid a cwd-dependent relative--env-file=.env).Suspected Root Cause
reference/scripts/run_actor.jsis written as an ESM module, but it is being executed in a CommonJS context:package.jsonwith"type": "module"in the script’s package scope, and/or--env-file=.envis cwd-dependent; Claude Code’s execution cwd may differ from the user’s project directory.Workarounds (Temporary)
package.jsoncontaining:{ "type": "module" }...\reference\scripts\so Node treats
run_actor.jsas ESM. (This is a cache directory, so updates may overwrite it.).mjs(also not ideal for a cached/published artifact).--env-file=...instead of relying on.envin cwd.Suggested Fix
Any of the following would address the ESM crash:
package.jsonwith"type": "module"in the appropriate scope forreference/scripts/run_actor.js.run_actor.jstorun_actor.mjsand update the invocation accordingly.require) to avoid ESM scope issues (less preferred).And for token loading reliability:
--env-file=.envby default (or clearly document required cwd / expected.envlocation), or~/.claude/.envon all platforms.Reference