Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The module was compiled against a different Node.js version #1942

Closed
1 task done
hzaun opened this issue Dec 7, 2021 · 4 comments
Closed
1 task done

The module was compiled against a different Node.js version #1942

hzaun opened this issue Dec 7, 2021 · 4 comments

Comments

@hzaun
Copy link

hzaun commented Dec 7, 2021

Issue

⚠ Error: The module '/Users/***/functions/node_modules/canvas/build/Release/canvas.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 64. 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 tryImporting (pkg/prelude/bootstrap.js:1736:37)
at process.dlopen (pkg/prelude/bootstrap.js:1762:5)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1186:18)
at Module.load (internal/modules/cjs/loader.js:984:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1024:19)
at Module.require (pkg/prelude/bootstrap.js:1338:31)
at Module.Hook._require.Module.require (/Users/lenskart/Work/FirebaseConsumer/functions/node_modules/require-in-the-middle/index.js:80:39)
at require (internal/modules/cjs/helpers.js:72:18)
at Object. (/Users/lenskart/Work/FirebaseConsumer/functions/node_modules/canvas/lib/bindings.js:3:18)
⚠ We were unable to load your functions code.

Your Environment

  • Version of node-canvas (output of npm list canvas or yarn list canvas): canvas@2.6.1 / 2.8.0
  • Environment (e.g. node 4.2.0 on Mac OS X 10.8): v10.16.0 on MacOS X @10.14.6
  • tcs @4.5.2
  • firebase @9.22.0
  • node @10.16.0

I understand this is a duplicate issue, but the solutions in SO/ these threads here didn't help:

I have compiled the solutions I've tried, as they might be of help to others.

What I've tried:

1. Reinstall canvas

  • Delete node_modules

  • Delete package-lock.json

  • npm uninstall canvas

  • npm i

2. Rebuild canvas [@obihill]

  • Delete node_modules directory

  • npm install

  • npm rebuild --build-from-source canvas

3. Rebuild canvas and update its binary [SO]

  • npm rebuild canvas --update-binary

4. Install using Homebrew [Canvas Wiki]

  • brew install pkg-config cairo pango libpng jpeg giflib librsvg

5. Use the latest version of canvas:

  • npm uninstall canvas

  • npm i canvas@latest
    [2.6.1 -> 2.8.0]

6. Verify cache content after uninstalling

  • npm uninstall canvas

  • npm cache verify

  • npm i canvas
    [still get NODE_MODULE_VERSION error while running functions]

7. Parallel reinstall of canvas

(a partially-working solution)

I did a local serve of my project, then installed canvas in parallel:

TERMINAL1: npm uninstall canvas

TERMINAL1: npm cache verify

  • Delete/ comment usages of canvas in my code

TERMINAL1: tsc && firebase serve --only hosting,functions
[tsc --watch && firebase serve --only hosting,functions doesn't work as intended]

TERMINAL2: npm i canvas
[no error this time]

TERMINAL1: Stop serving, and serve again
[don't get NODE_MODULE_VERSION error anymore]

However, I have to build my project again each time I make code changes.

Of course, if I delete package-lock.json, I get the same issue again :(

@LinusU
Copy link
Collaborator

LinusU commented Dec 7, 2021

It seems like you are using Node.js 10.x to install the module, but are then running it with Node.js 12.x.

You say that you are using Node.js 10.16.0. Could you update that to Node.js 12.22.7 and try again?

@hzaun
Copy link
Author

hzaun commented Dec 7, 2021

Thanks @LinusU ! There's some issue with graceful-fs node 12.22.7, but I did try with node 12.18.2, and it worked!

Looks like our GCP function was created using Node 12 (the local engine uses node 10).

@hzaun
Copy link
Author

hzaun commented Dec 8, 2021

Was able to successfully update to node 12.22.7 by reinstalling graceful-fs (SO)

@TA2k
Copy link

TA2k commented Feb 16, 2022

PR to solve the issue
#1982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants