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
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.
Terminal
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.
JavaScript
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.
Related guides
Node ERR_MODULE_NOT_FOUND on ESM Import in CI - Fix Specifier ResolutionFix the Node.js ERR_MODULE_NOT_FOUND error in CI by adding the missing file extension or correcting the ESM i…
Node "Error: Cannot find module 'X'" in CI - Fix Module ResolutionFix the Node.js "Error: Cannot find module" crash in CI by correcting the path, extension, or build output th…
Node ERR_PACKAGE_PATH_NOT_EXPORTED in CI - Fix the Exports Map SubpathFix the Node.js ERR_PACKAGE_PATH_NOT_EXPORTED error in CI by importing a subpath the package exports map expo…