esbuild "Could not resolve '<package>'" - Fix Missing Deps in CI
esbuild followed an import and could not resolve it. The package is not installed, the path is wrong, or it is a Node built-in/peer that should be marked external for the build platform.
What this error means
The build fails with Could not resolve "<package>", naming the importing file and offering a hint (mark it external, or check the path). It is deterministic.
✘ [ERROR] Could not resolve "lodash-es"
src/util.ts:1:23:
1 │ import debounce from "lodash-es"
╵ ~~~~~~~~~~~~
You can mark the path "lodash-es" as external to exclude it from the bundle.Common causes
Dependency not installed or not declared
The package is missing from node_modules/package.json, so a clean npm ci build cannot resolve it.
Wrong path or subpath not exported
A relative path typo, a case mismatch, or a deep subpath the package does not export.
Node built-in not externalized for a browser/Node target
Importing a Node core module (fs, path) in a build that does not mark it external, or for the browser, fails resolution.
How to fix it
Install the dependency and fix the path
npm install lodash-es
npm ls lodash-es # confirm it's a direct dependencyMark platform/peer modules external
Externalize Node built-ins (or peers in a library build) so esbuild does not try to bundle them.
// esbuild build options
{ platform: 'node', external: ['react', 'react-dom'] }How to prevent it
- Declare every imported package as a direct dependency.
- Set the correct
platformand externalize built-ins/peers intentionally. - Match import paths and casing to what the package actually exports.