Node "Cannot find package 'X' imported from" in CI - Fix the ESM Package Resolution
This ESM error means the loader resolved a bare import specifier to a package that is not installed under node_modules on the CI runner.
What this error means
A program run as ESM throws Error: Cannot find package "<name>" imported from <file>. The package is missing or was a dev dependency pruned in CI.
node:internal/modules/esm/resolve:854
Error: Cannot find package 'lodash-es' imported from
/home/runner/work/app/app/src/index.js
at packageResolve (node:internal/modules/esm/resolve:854:9) {
code: 'ERR_MODULE_NOT_FOUND'
}Common causes
The package is not installed in CI
A dependency is imported but missing from package.json, or was a devDependency omitted by a production install.
A bare specifier that should be a relative path
An import meant to point at a local file was written as a bare package specifier.
How to fix it
Install the package as the right dependency type
- Add the package to dependencies if it is needed at runtime.
- Reinstall and commit the lockfile.
npm install lodash-esUse a relative path for local modules
- If the import targets a local file, make it a relative path with an extension.
import { fn } from './lib/fn.js';How to prevent it
- Keep runtime imports in dependencies (not devDependencies), commit the lockfile, and distinguish bare package specifiers from relative paths.