NPM module canvas was compiled against a different Node.js version using NODE_MODULE_VERSION 88
Asked Answered
S

2

11

I am trying to use the NPM version of canvas as well as an NPM module to merge images. However it Canvas seems to not want to load. I get an error everytime I require it and run the script.

This answer didn't really seem to help as I tried all of the solutions but it seemed to be talking about bcrypt and electron.

I am running node v12.16.3 with npm version 6.14.10 and my canvas version in my package.json is ^2.6.1

My complete error message:

Error: The module '\\?\C:\...\node_modules\canvas\build\Release\canvas.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 88. This version of Node.js requires
NODE_MODULE_VERSION 72. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1183:18)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\...\node_modules\canvas\lib\bindings.js:3:18)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\...\node_modules\canvas\lib\canvas.js:9:18)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
Syncretism answered 13/1, 2021 at 15:24 Comment(4)
Have you tried npm rebuild or npm install?Waltraudwaltz
Have yout ried to compile it on your system? -> npmjs.com/package/canvas#compilingBethune
I tried deleting my package-lock.json and node-modules and then running npm install but nothing and npm rebuild seems to fail?Syncretism
Does this answer your question? Node - was compiled against a different Node.js version using NODE_MODULE_VERSION 72Roughen
C
26

Came across this when looking for the same error and reinstalling/deleting my node_modules folder did nothing. Using npm rebuild canvas --update-binary worked for me however.

I found this solution at a different answer for a similar error at this question, just changed it to fit canvas. Leaving this incase someone else comes across this too.

Crissum answered 11/6, 2021 at 10:14 Comment(2)
When you come across a question that you know is already have been posted on SO, flag it as duplicate, instead of repeating answers and linkingRoughen
@Roughen it's similar, but not the same (different package).Sadick
L
1

I had this trouble too with canvas - if you are running tests from your IDE - ensure that you use the same node version to run the tests as the node version you used to install the binary. In my case I had node 21 as my node version for running tests, but used node 20 to install the canvas module. Check your IDE settings (in intellij idea I have a dropdown list of all node versions, ensure they match). Setting the node version to 20 in my IDE solved the problem.

Laurin answered 3/7, 2024 at 8:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.