Visual Studio Code NodeJS debugger uses different version than installed

1k views Asked by At
VSCode Version:1.8.1
OS Version:Windows 10 x64 and Kali Linux x64

Hey I am trying to make VSCode extension that uses nodehun module https://www.npmjs.com/package/nodehun which dynamically links hunspell library using node-gyp I have on windows 10 using commandline node:

process.version = 7.4.0 process.arch = x64

If I try to use nodehun methods manually using NodeJS command line interface everything works fine but if I try to use it in extension.js and debug via Visual Code I have:

process.version = 6.5.0 process.arch = ia32

That makes me encounter with error

Error: %1 is not a valid win32 application.

I don't really understand how can VSCode use NodeJS version which I don't have installed. Similarly on Kali linux x64 I have:

process.version = 7.4.0 process.arch = x64

and debugging extension via VSCode

process.version = 6.5.0 process.arch = x64

which at least have the same arch so I encounter with error

Error: Module version mismatch. Expected 50, got 51

this is really interesting because there is no node_module_version = 50, as you can see here on the nodejs website:

https://nodejs.org/en/download/releases/

there is only node_module_version 48 for versions 6.x.x and 51 for versions 7.x.x.

So I tried to rebuild with on windows 10 x64 npm rebuild --target=6.5.0 --arch=ia32 and then debug via VSCode with error

Error: A dynamic link library (DLL) initialization routine failed.

And on Kali linux x64 npm rebuild --target=6.5.0 and then debug

Error: Module version mismatch. Expected 50, got 48

I think there might be a trick in debug settings. My launch.json looks like this:

// A launch configuration that launches the extension inside a new window

    {
        "version": "0.1.0",
        "configurations": [
            {
                "name": "Launch Extension",
                "type": "extensionHost",
                "request": "launch",
                "runtimeExecutable": "${execPath}",
                "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
                "stopOnEntry": false
            },
            {
                "name": "Launch Tests",
                "type": "extensionHost",
                "request": "launch",
                "runtimeExecutable": "${execPath}",
                "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/test" ],
                "stopOnEntry": false
            }
        ]
    }

How is it possible that VSCode debugger have different NodeJS version that I have installed and using node_module_version = 50? Any suggestions or workaround how could I make it work?

2

There are 2 answers

1
Denis On

VS Code runs extensions on the node version that is built into electron. You can use module electron-rebuild

 ./electron-rebuild --version="electron_version" --arch="your_vscode_architecture" --which-module="module_name_to_rebuild"

To build your module :)

0
roguexiaohuihui On

I also have this error with node_module_version=69 when using node_pty.

Similarly, node_module_version = 50 is also a version of electron. You just need to look at the version information of your current vscode, find its corresponding electron version number, and then compile it with its version number. You can refer to the following command:

set npm_config_disturl="https://atom.io/download/electron"
set npm_config_target=4.0.4
set npm_config_runtime="electron"
set npm_config_cache=~\.npm-electron
npm i
endlocal