npm install fails with EACCES, ERESOLVE or out of memory: what to do

When npm install fails, the message is usually long, but the cause fits one of half a dozen families. The short answer: look in the output for the first line that starts with npm ERR! (or npm error in the newest versions) and the code that follows it (EACCES, ERESOLVE, ENOSPC…). The code says nearly everything. This article is for shared hosting (cPanel) and for a VPS.

The code, and what it means

What you see What it is What to do
EACCES (permission denied) npm tried to write somewhere your user cannot, nearly always because of a -g (global install) or a folder that belongs to another user. In cPanel do not use global installs or sudo: install in the project, inside the application’s environment. On a VPS, do not run sudo npm install in the project: fix the folder owner (chown) instead of working around it. See also permission denied in a Node.js or Python app.
ERESOLVE (unable to resolve dependency tree) Two libraries ask for incompatible versions of a third (a peer dependency conflict). The clean fix is to line the versions up. To move on right now, npm install --legacy-peer-deps ignores the conflict. --force is more aggressive: use it only if you know what the conflict means.
JavaScript heap out of memory Node ran out of the memory it is allowed while building or installing. Build on your computer and upload the result. On a VPS you can raise Node’s limit, for instance with NODE_OPTIONS=--max-old-space-size=2048 (the value is an example), if the machine has free memory.
ENOSPC or “quota exceeded” No disk space, or the account’s file (inode) limit was reached. See the account limits. Delete what you do not use and install only what production needs.
node-gyp, gcc, Python.h A library has parts that need compiling, and the tools are missing. Look for a version with a prebuilt binary, or a pure JavaScript alternative. On a VPS you can install the system’s build tools.
ETIMEDOUT, ENOTFOUND The server could not reach the npm registry: network or DNS. Try again; check the connection with curl -I https://registry.npmjs.org.
EINTEGRITY npm’s cache got corrupted. npm cache verify, then install again.

The routine that fixes most of them

1 Check the Node version the project asks for (the engines field in package.json): node -v
npm -v
A wrong version produces errors that look like something else.
2 Delete and start again, from the lockfile: rm -rf node_modules
npm ci
In cPanel, the “Run NPM Install” button does the install part, in the right environment.
3 Read the first error message, not the last. The last lines are usually just npm’s summary.
4 Changed the Node version? Reinstall the dependencies: some have parts compiled for one specific version.
Do not use sudo to silence an EACCES. It makes the install pass and leaves project files owned by root, which causes the next error, and another after that. In cPanel there is no root at all. If the problem is a folder with the wrong owner, fix the owner.
Keep the whole message before deleting anything: npm writes a log file (the path appears at the end of the error). If you ask for help, that is what helps the reader most. To choose the right manager and lockfile, see npm, yarn or pnpm.

The install fails and you cannot see why? Send us the domain and the first line of the error.

Open a support ticket

SEE ALSO

npm, yarn or pnpm: which to use

Node.js in cPanel: choosing the version and using npm

The limits nobody advertises: inodes, processes and memory

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from 5.940,00 Kz/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?