How to fix npm ERR! gyp ERR! stack Error: ENOENT: no such file or directory, stat '/usr/include/node/common.gypi' in npm
This error occurs when node-gyp can't find the Node.js development headers needed to compile native modules. Usually caused by missing or corrupted header files.
Quick fix
Fixes npm ERR! gyp ERR! stack Error: ENOENT: no such file or directory, stat '/usr/include/node/common.gypi'
node-gyp install- Download Node.js headers
- Clear and re-download headers
- Install Node.js development package (Linux)
- Set nodedir explicitly
node-gyp installnpm ERR! gyp ERR! stack Error: ENOENT: no such file or directory, stat '/usr/include/node/common.gypi'
What this error means
The ENOENT error for `common.gypi` means node-gyp can't find the Node.js development headers. These headers contain the C/C++ definitions needed to compile native modules that interface with Node.js internals. node-gyp looks for these headers in several locations: - Downloaded in ~/.node-gyp/ - System-installed in /usr/include/node/ - Bundled with Node.js installation This error typically occurs when: - Headers weren't downloaded for your Node.js version - Headers are corrupted or incomplete - Using a Node.js version installed without headers - The nodedir configuration points to wrong location
Typical symptoms
- npm install fails with ENOENT for common.gypi
- Error mentions /usr/include/node/ or .node-gyp directory
- Native module compilation fails to start
- Happens after Node.js version change
Common causes
- Node.js development headers not installed
- Headers corrupted or incomplete in .node-gyp
- Node.js installed without development files
- nodedir config pointing to wrong location
- Version mismatch between Node.js and cached headers
How to fix "npm ERR! gyp ERR! stack Error: ENOENT: no such file or directory, stat '/usr/include/node/common.gypi'"
Tell node-gyp to download headers for your Node.js version:
node-gyp installThis downloads headers to ~/.node-gyp/ (or %USERPROFILE%\.node-gyp on Windows).
If headers are corrupted, remove and re-download:
# Remove cached headers
rm -rf ~/.node-gyp
# Re-download
node-gyp install
# Retry npm install
npm installIf using system Node.js, install the dev package:
Debian/Ubuntu:
sudo apt-get install nodejs-devRHEL/CentOS/Fedora:
sudo yum install nodejs-devel
# or
sudo dnf install nodejs-develPoint node-gyp to the correct headers location:
# Find your Node.js version
node --version
# Set nodedir (adjust path as needed)
npm config set nodedir ~/.node-gyp/$(node --version | cut -c 2-)
# Or for a single install
npm install --nodedir=/path/to/node/headersOlder node-gyp versions may have issues finding headers:
npm install -g node-gyp@latestAdvanced notes
nvm users: When switching Node.js versions with nvm, headers for the new version may not exist. Run node-gyp install after switching versions.
Offline environments: If you can't download headers, you can manually copy them from another machine. Place them in ~/.node-gyp/VERSION/.
Header version matching: The headers must match your exact Node.js version. node-gyp uses your current Node.js version to determine which headers to download.
System vs nvm Node.js: If you have both system Node.js and nvm, ensure you're using consistent versions. Mixing can cause header mismatches:
which node # Check which Node.js is being used
node --versionFrequently asked questions
- What does "npm ERR! gyp ERR! stack Error: ENOENT: no such file or directory, stat" mean?
- js development headers. js internals.
- How do I fix "npm ERR! gyp ERR! stack Error: ENOENT: no such file or directory, stat"?
- This error occurs when node-gyp can't find the Node.js development headers needed to compile native modules. Usually caused by missing or corrupted header files.
- What causes "npm ERR! gyp ERR! stack Error: ENOENT: no such file or directory, stat"?
- Node.js development headers not installed Headers corrupted or incomplete in .node-gyp Node.js installed without development files
- Is the "npm ERR! gyp ERR! stack Error: ENOENT: no such file or directory, stat" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐GitHub: node-gyp(GitHub)
- ๐Docs: node-gyp guide(Official Docs)
- ๐ฌSO: node-gyp headers(Stack Overflow)