-1

I have test.js:

const { createCanvas, loadImage } = require('canvas');

console.log('hi');

launch.json

...
    {
      "name": "test script",

      "type": "node",
      "request": "launch",
      "runtimeExecutable": "node",
      "skipFiles": ["<node_internals>/**"],
      "program": "${workspaceFolder}/test.js",
      "console": "integratedTerminal"
    },
...

When I run test script in the VSCode debugger I get

internal/modules/cjs/loader.js:1144
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: The module '/Users/me/Documents/gift_registry_business_idea/backend/node_modules/canvas/build/Release/canvas.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 93. This version of Node.js requires
NODE_MODULE_VERSION 83. 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:1144:18)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/Users/dashiellbarkhuss/Documents/gift_registry_business_idea/backend/node_modules/canvas/lib/bindings.js:3:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12) {
  code: 'ERR_DLOPEN_FAILED'
}

However, test.js works fine if I run node test.js in the terminal or if I run this in launch.json, changing node to nodemon

...
    {
      "name": "test script",

      "type": "node",
      "request": "launch",
      "runtimeExecutable": "nodemon",
      "skipFiles": ["<node_internals>/**"],
      "program": "${workspaceFolder}/test.js",
      "console": "integratedTerminal"
    },
...

Deleting node_modules and runing npm rebuild or npm install didn't work.

4
  • What's launch.json used by? Because that's not a standard Node/NPM thing. Commented Mar 13, 2023 at 21:42
  • from github.com/Automattic/node-canvas/issues/1942 possibly caused by installing node-canvas with a different version of nodeJS than you try to run node-canvas with. from github.com/Automattic/node-canvas/issues/1879 try deleting node-canvas's folder in node_modules and then running npm install again. Does that answer your question / solve your problem? (found those by googling ""canvas/build/Release/canvas.node" "was compiled against a different Node.js version using"") Commented Mar 13, 2023 at 21:44
  • @Mike'Pomax'Kamermans it's a VSCode thing Commented Mar 13, 2023 at 21:49
  • @user canvas was fine, I think it was the node version used by launch.json. It didn't match the nvm version. adding "runtimeVersion": "16.17.1" worked Commented Mar 13, 2023 at 21:51

1 Answer 1

0

https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_multi-version-support

Multi version support If you are using 'nvm' (or 'nvm-windows') to manage your Node.js versions, >it is possible to specify a runtimeVersion attribute in a launch >configuration for selecting a specific version of Node.js:

{
 "type": "node",
 "request": "launch",
 "name": "Launch test",
 "runtimeVersion": "14",
 "program": "${workspaceFolder}/test.js"
}

I added the `runtimeVersion to match my environment, and it worked. But I'd like to know if there's a way to set the node version without having to set it individually on each launch configuration.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.