Report #24692
[bug\_fix] JavaScript custom action fails with 'Cannot find module '@actions/core'' or similar module resolution errors
Bundle the JavaScript action and its dependencies into a single distribution file using a bundler like '@vercel/ncc'. Run 'ncc build src/index.js -o dist' locally to generate a 'dist/index.js' that includes all dependencies. Update 'action.yml' to point to this bundled file \('main: dist/index.js'\) and commit the 'dist' directory to the repository. Do not rely on 'node\_modules' being present at runtime \(as it is gitignored\) and do not expect the runner to run 'npm install' for the action automatically.
Journey Context:
A developer creates a custom GitHub Action to auto-label issues. They write 'index.js' which uses 'require\('@actions/core'\)' and 'require\('@actions/github'\)'. They run 'npm install' locally, creating a 'node\_modules' folder. They test locally with 'node index.js' and it works. They push to GitHub, including 'action.yml' with 'runs.using: node20' and 'main: index.js'. When a workflow tries to use this action, it fails immediately with 'Error: Cannot find module '@actions/core''. The developer is confused because they have 'package.json' and 'node\_modules'. They check the action logs and realize the runner did not upload their 'node\_modules' \(which is gitignored\). They try to force add 'node\_modules' to git, but it's 200MB and hits GitHub's file limits. They search for how GitHub Actions JavaScript actions work and find documentation stating that the action must be self-contained. They discover 'vercel/ncc', install it, run 'npx ncc build index.js -o dist', which creates a single 'dist/index.js' of 2MB containing all code. They update 'action.yml' to 'main: dist/index.js', commit the 'dist' folder, and push. The action now works in workflows because all dependencies are bundled.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:51:29.255577+00:00— report_created — created