Node.js cannot find the compiled .node file of a native module
Error: Could not load the bindings file. Tried:Short answer
The package needs a compiled .node addon, and none was found in the folders it searches. The usual reasons are install scripts that never ran, a Node.js version change since the install, or a platform that has no prebuilt binary. Print err.tries to see the searched paths, then run npm rebuild or use a supported platform.
Fix it fast
1Find out which cause you have
The bindings package attaches the list of searched paths to the error. Print it and compare it with what really exists in the module's build folder. Replace your_addon with the addon's name.
node -e "try { require('bindings')('your_addon') } catch (e) { console.log(e.tries) }" find node_modules -name "*.node" -not -path "*/node_modules/*/node_modules/*" | head2Match what you see, then jump to its fix
- 1
No .node file exists under the package; the install used --ignore-scripts or a CI setting that disables scriptsInstall scripts were skipped, so nothing was builtFix - 2
It worked before an upgrade or a version-manager switch, and a different Node.js now runs the appNode.js was upgraded or switched after the packages were installedFix - 3
Cannot find module '../build/Release/canvas' on a platform that the package does not ship binaries forNo prebuilt binary exists for this operating system or CPU (canvas)Fix
- 1
What does the error look like?
Error: Could not load the bindings file. Tried:Error: Cannot find module '../build/Release/canvas'
Cause 1 of 3
Install scripts were skipped, so nothing was built
1Check
npm does not run package scripts when ignore-scripts is true, and a native addon is built or fetched by its install script.
npm config get ignore-scripts
grep -n "ignore-scripts" .npmrc ~/.npmrc 2>/dev/null2Fix
Run the lifecycle scripts again with rebuild, with ignore-scripts overridden to false. Foreground scripts show the build output.
npm rebuild --ignore-scripts=false --foreground-scripts3Verify
A .node file now exists and the module loads.
find node_modules -name "*.node" | head
node -e "require('canvas'); console.log('ok')"Confirmed by docs.npmjs.com
Cause 2 of 3
Node.js was upgraded or switched after the packages were installed
1Check
Compiled addons are tied to the Node.js version they were built for. The npm documentation names installing a new Node.js version as the case where you recompile all C++ addons.
node -v && npm ls canvas2Fix
Rebuild every native package with the Node.js you run, or delete node_modules and install again.
npm rebuild
# or
rm -rf node_modules && npm ci3Verify
Start the app with the same Node.js that ran the rebuild.
node -e "console.log(process.version)" && node app.jsConfirmed by docs.npmjs.com
Cause 3 of 3
No prebuilt binary exists for this operating system or CPU (canvas)
1Check
The canvas README lists prebuilt binaries for macOS x64 and arm64, Linux x64, x86 and arm64 (glibc or musl), Linux arm and riscv64 (glibc only) and Windows x64, x86 and arm64.
node -p "process.platform + ' ' + process.arch"2Fix
Run the app on a listed platform. For an unlisted system, the README (current v4 pre-release) says to go into the package folder and run zig build, and notes you may need to adjust build.zig.
cd node_modules/canvas
zig build3Verify
The package loads on that machine.
node -e "require('canvas'); console.log('ok')"Confirmed by github.com
How do I stop it coming back?
- Run npm ci or npm rebuild after every Node.js version change, in development and in CI.
- Build the production image with the same Node.js version and platform that runs it, not by copying node_modules from a laptop.
- Keep ignore-scripts off for packages that compile or download a native addon.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix