How to fix npm ERR! In file included from ../node_modules/node-addon-api/napi.h in npm
This error occurs during native module compilation when the node-addon-api headers can't be found or have compatibility issues. Usually caused by missing include paths or version mismatches.
Quick fix
Fixes npm ERR! In file included from ../node_modules/node-addon-api/napi.h
npm update node-addon-api
# Or install latest
npm install node-addon-api@latest- Update node-addon-api
- Download Node.js headers
- Install build tools
- Clean reinstall
npm update node-addon-api# Or install latestnpm install node-addon-api@latestnpm ERR! In file included from ../node_modules/node-addon-api/napi.h
What this error means
The error referencing `node-addon-api/napi.h` indicates a problem compiling a native module that uses Node-API (formerly N-API). Node-API is a stable ABI for building native addons that work across Node.js versions. This error typically means: - The C++ compiler can't find the napi.h header file - There's a version mismatch between node-addon-api and Node.js - The binding.gyp file has incorrect include paths - Node.js headers weren't downloaded properly The error message usually continues with the specific compilation error (missing file, type error, etc.).
Typical symptoms
- Compilation error mentioning node-addon-api/napi.h
- Build fails during npm install of native module
- Error about 'No such file or directory' for napi.h
- Type conversion errors in napi code
Common causes
- node-addon-api version incompatible with Node.js version
- Missing node-addon-api dependency
- Incorrect include paths in binding.gyp
- Node.js headers not downloaded by node-gyp
- Build tools not properly installed
How to fix "npm ERR! In file included from ../node_modules/node-addon-api/napi.h"
Ensure you have a compatible version:
npm update node-addon-api
# Or install latest
npm install node-addon-api@latestFor Node.js 20.12+, you need node-addon-api 7.1.0 or later.
node-gyp needs Node.js header files:
# Remove old headers
rm -rf ~/.node-gyp
# Download fresh headers
node-gyp install
# Rebuild
npm rebuildEnsure you have C++ compilation tools:
Linux:
sudo apt-get install build-essential python3macOS:
xcode-select --installWindows:
npm install --global windows-build-toolsDo a complete clean install:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installLook at the full error message. Common issues:
"napi.h: No such file or directory": node-addon-api not installed or binding.gyp has wrong include path.
Type conversion errors: Usually version mismatch. Update node-addon-api.
"nogc_finalize" errors (Node.js 20.12+): Update to node-addon-api 7.1.0+.
Advanced notes
For package maintainers: Ensure binding.gyp includes node-addon-api:
{
"targets": [{
"target_name": "addon",
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"]
}]
}Node.js 20.12+ breaking changes: The Node-API introduced changes that require node-addon-api 7.1.0+. If you can't upgrade the package, you may need to use an older Node.js version temporarily.
NAPI_VERSION: Some packages require specific NAPI versions. Check the package documentation for requirements.
Prebuild: For packages you maintain, consider using prebuild to ship precompiled binaries and avoid end-user compilation:
npm install --save-dev prebuild prebuild-installFrequently asked questions
- What does "npm ERR! In file included from ../node_modules/node-addon-api/napi.h" mean?
- h indicates a problem compiling a native module that uses Node-API (formerly N-API). js versions. ).
- How do I fix "npm ERR! In file included from ../node_modules/node-addon-api/napi.h"?
- This error occurs during native module compilation when the node-addon-api headers can't be found or have compatibility issues. Usually caused by missing include paths or version mismatches.
- What causes "npm ERR! In file included from ../node_modules/node-addon-api/napi.h"?
- node-addon-api version incompatible with Node.js version Missing node-addon-api dependency Incorrect include paths in binding.gyp
- Is the "npm ERR! In file included from ../node_modules/node-addon-api/napi.h" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐GitHub: node-addon-api(Official Docs)
- ๐Node.js docs: N-API(Official Docs)
- ๐ฌStack Overflow: node-addon-api(Stack Overflow)