Learning objectives
After reading this article you will be able to:
- Tell from the log which common cause broke npm install
- Fix peer dependency conflicts, native modules and Node version mismatches without risky workarounds
- Prevent missing devDependencies, out-of-sync lockfiles and out-of-memory installs on the next deploy
On this page
The deploy failed before your app printed a single line, and the log ends in a stack of npm error lines. What broke was the dependency install, not your code. Nearly every npm install failure on a server comes down to a few causes, and each one leaves a signature in the log.
This guide goes from the message to the fix. For the general routine of reading a long log, see how to read build errors.
How do you tell which error broke the install?#
Scroll to the first npm error code line (older npm versions print npm ERR! code). Everything after it is detail or consequence. With the code in hand, use this table:
| What the log shows | Cause | Fix |
|---|---|---|
code ERESOLVE |
Peer dependency conflict | Upgrade the package that wants the old version |
gyp ERR! and command sh -c node-gyp rebuild |
Native module with no prebuilt binary and no build tools | A version with prebuilt binaries or a JavaScript alternative |
NODE_MODULE_VERSION on start |
node_modules copied from another machine |
Do not upload node_modules |
EBADENGINE |
Node version outside engines |
Align the Node version |
code EUSAGE from npm ci |
Lockfile out of sync | npm install locally and commit the lockfile |
not found in a script or Cannot find module |
Missing devDependency with NODE_ENV=production |
Move it to dependencies or build beforehand |
signal SIGKILL or exit code 137 |
Out of memory | More memory or less compiling during install |
Why does ERESOLVE show up?#
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: my-app@1.0.0
npm error Found: react@19.0.0
npm error node_modules/react
npm error react@"19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.0.0" from some-library@2.1.0
npm error node_modules/some-library
npm error some-library@"^2.1.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution.A peer dependency is a package a library requires your project to provide, within a version range. npm installs peer dependencies by default and, according to its docs, a conflicting requirement can become an error when the tree cannot be resolved. Here, some-library wants react in one range and the project provides another. The last line suggests two flags, but warns that the result may be broken.
Fix it in this order:
- Upgrade
some-libraryto a version whose range includes yours. - If none exists, align the version of the package you control.
- Only as a last resort, use
--legacy-peer-deps. The docs say it makes npm ignorepeerDependenciesentirely, so the conflict stays and can surface at runtime.
If you adopt the flag, write legacy-peer-deps=true to the .npmrc at the project root. npm reads that file on every install, so your machine, CI and the server resolve the same tree. Avoid --force: the docs warn that it removes protections against unfortunate side effects.
What do you do when node-gyp fails?#
A native module is a package with C or C++ code that becomes a .node file compiled for a specific system. node-gyp is the tool that compiles those modules when there is no prebuilt binary to download:
npm error code 1
npm error path /app/node_modules/some-native-addon
npm error command failed
npm error command sh -c node-gyp rebuild
npm error gyp ERR! configure error
npm error gyp ERR! stack Error: Could not find any Python installation to useWhen other tools are missing, the stack line changes to Error: not found: make, or the compiler fails and you see Error: `make` failed with exit code: 2.
Two things have to go wrong at once. First, the package has no prebuilt binary for your mix of system, architecture and Node version, which is common when your Node version is newer than the package. Second, the machine lacks what node-gyp needs on Linux: Python, make and a C/C++ compiler such as GCC.
The fixes, from simplest to most work:
- Upgrade the package to a version that publishes binaries for your Node version.
- Switch to a pure JavaScript alternative or a built-in Node feature. For password hashing, for example,
crypto.scryptships with Node, as shown in the best way to store passwords. - On a machine you control, such as a VPS or a Docker image, install Python,
makeand the compiler.
What about the NODE_MODULE_VERSION error?#
This one shows up on start, not during the install:
Error: The module '/app/node_modules/some-native-addon/build/Release/addon.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION N. This version of Node.js requires
NODE_MODULE_VERSION M. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).The binary was compiled for another Node version. The classic cause is uploading the node_modules from your machine; if it came from another operating system, the error can come from the system itself when it opens the .node file (on Linux, something like invalid ELF header). The fix is the same: do not upload node_modules and let the install run on the server. Packages that ship one binary per platform, such as sharp, also warn that a package-lock.json shared across different systems can cause install problems because of a known npm bug.
Why does npm warn about EBADENGINE?#
A package's engines field says which Node versions it accepts. By default, npm only warns:
npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE package: 'some-lib@3.0.0',
npm warn EBADENGINE required: { node: '>=N' },
npm warn EBADENGINE current: { node: 'vM', npm: 'X.Y.Z' }
npm warn EBADENGINE }The install goes on, and the breakage, if any, shows up on start: a SyntaxError or a function that does not exist in the running version. With engine-strict=true in .npmrc, the warning becomes an error and the install stops:
npm error code EBADENGINE
npm error engine Unsupported engine
npm error engine Not compatible with your version of node/npm: some-lib@3.0.0The fix is to run a Node version on the server that satisfies the named package's engines, or to pin a version of the package that accepts yours. Declare the version you tested in your own package.json engines, so the mismatch shows up early. Version gaps between your machine and the server also explain many cases of works locally but not in production.
Why does npm ci complain about the lockfile?#
npm error code EUSAGE
npm error
npm error `npm ci` can only install packages when your package.json and package-lock.json are in sync. Please update your lock file with `npm install` before continuing.
npm error
npm error Missing: express@5.1.0 from lock filenpm ci is the install command for automated builds: it requires a package-lock.json and fails instead of updating it when it does not match package.json. Typical causes are editing package.json by hand, leaving the lockfile out of the commit or mixing package managers. Run npm install on your machine, commit package-lock.json and deploy again.
Why are devDependencies missing?#
When NODE_ENV is production, the npm docs say the default of the omit option becomes dev: npm install leaves devDependencies out. Everything works until a script or your code needs one of them. A "build": "tsc" fails with something like tsc: not found (the exact text depends on the shell), and importing a missing package raises the "Cannot find module" error.
Three ways out:
- Move whatever runs on the server to
dependencies: the compiler, the ORM CLI, any package imported at runtime. - Install everything with
npm install --include=dev, if you control the install command. - Build beforehand, in CI, and ship the output. The options for TypeScript are in how to run TypeScript in production.
What if the install runs out of memory?#
Compiling a native module or running a heavy build in postinstall are the memory peaks of an install. When the system kills the process, npm shows the signal:
npm error path /app/node_modules/some-native-addon
npm error command failed
npm error signal SIGKILL
npm error command sh -c node-gyp rebuildOutside npm, the same event shows up as exit code 137, which is 128 plus signal 9, explained in exit code 137 and other exit codes. If what overflows is the V8 heap in a JavaScript script, the message ends in JavaScript heap out of memory.
Give the install environment more memory, prefer packages with prebuilt binaries so nothing compiles, and move heavy builds out of postinstall. For the heap, NODE_OPTIONS=--max-old-space-size=<MiB> raises the limit, but it only helps if the machine actually has that memory. The full diagnosis is in out-of-memory errors.
How do you keep it from coming back?#
- Reproduce the server install: delete
node_modulesand runnpm ci --omit=dev. - Commit the lockfile, never
node_modules. - Use the same Node version on your machine, in CI and on the server.
- Run the install in CI before the deploy, so failures show up far from production.
How to do this on Square Cloud#
Square Cloud's Node.js runtime has no build step: on start, the platform runs npm install when there is no node_modules, with NODE_ENV=production. That is why devDependencies are left out, as in the section above, postinstall runs and build does not. Environment variables already exist during the install, and npm's output shows up in the application logs, so the first npm error code line is there.
Since the install only runs when there is no node_modules, do not upload yours: with the folder in the upload, the server uses binaries compiled for your machine, which may fail to load there. If you use the CLI, list node_modules in squarecloud.ignore, which uses .gitignore syntax.
The Node.js version is chosen at deploy time, along with memory and the main file (or in squarecloud.app, which is optional and which the dashboard generates on deploy). Check that it satisfies your dependencies' engines. A memory overflow stops the application, and it does not come back on its own: if the log shows SIGKILL or heap out of memory, raise the RAM in its settings (one application can use up to 32 GB of the plan's pool) and start it again. To compile TypeScript or a front end, run the build in an external CI and upload the output, or put the build in the start command. See the details on Node.js hosting.
Deploy
Push from GitHub, the CLI or a ZIP and go live in seconds
FAQs
How do I fix npm ERR! code ERESOLVE?
Upgrade the package that asks for the old peer dependency version, or align the version of the package you control. The --legacy-peer-deps flag gets the install through, but it ignores every peer dependency, so the conflict is still there.
Why does npm install work on my machine but fail on deploy?
The server runs a different system, often a different Node version and, frequently, NODE_ENV=production. That changes which native module binaries fit, which packages accept that Node version and whether devDependencies get installed.
Should I upload my node_modules folder?
No. Native modules are compiled for one operating system, one architecture and, in many cases, one Node version, so a node_modules from your machine can break on the server. Ship package.json and the lockfile and let the install run there.
What does npm error signal SIGKILL mean during install?
The system killed the process, usually because it ran out of memory while an install script was compiling something. Give the install more memory or avoid compiling during it by using packages with prebuilt binaries.
npm install or npm ci on deploy?
In CI and automated builds, npm ci: it installs exactly what the lockfile says and fails if package.json and package-lock.json disagree. npm install can update the lockfile when they diverge and install versions you never tested.
More in Deploy
See all 38 articles- What are environment variables?Environment variables are key-value pairs the operating system hands to a process at startup. Learn to read them in Node.js and Python and keep tokens out of code.
- What is a deployment?A deployment takes a version of your code to a server, prepares it and starts it. See the stages, the methods and how to roll back when it goes wrong.
- How much RAM and CPU does my app need?Size RAM and CPU by measuring your app's real peak and adding about 30% headroom. Learn how to measure in Node.js, Python and Java and what to do if short.
- IaaS vs PaaS vs SaaS: the differences, with examplesIaaS rents machines, PaaS gives you an environment to run your code and SaaS delivers a finished app. Compare who is responsible for what, with examples.