You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m looking to build an extension but one of the packages I need to depend on is a native module. When I do an npm install it installs the package just fine, I can launch a node shell and interact with it, etc. But when I go to use the package from within my plugin I get an error as it’s trying to load the ia32 build of the native module not the x64 which was compiled by node-gyp.
A quick bit of debugging indicates that the problem stems by process.arch returning ia32 when running in VS Code when my machine is a x64 machine (Win10 x64).
So is there some way to either:
Have VS Code run an x64 process
Have VS Code’s ia32 process do my npm restore (and subsequent compile with node-gyp)
Otherwise I fear that my extension might be dead in the water 😦
Reacted by Thomas Mullen, David Lechner, Marek Lewandowski, Kim Kangho, Yukai Huang, Simon Chan, Christian Voigt, sjwl, stef-levesque, Matt Bierner and 32 more
Reacted by Tim Etchells, José Simões, Andrew Keats and Samuel Ainsworth
I'm doing some more investigation on this to see if I can unblock myself by getting an ia32 version of the module loaded, so I installed the x86 version of node.js, installed the native module (which in turned got the right binary).
npm_config_target= whatever value is there on electronVersion
npm_config_arch= whatever the bit architecture you need
HOME= something other that ~, like ~/.electron-gyp, so node-gyp and npm don't confuse themselves.
The extension package must contain the binaries for all platforms Code supports: win32-ia32, darwin, linux-ia32 and linux-x64. It would then dynamically require the correct binary for the running platform at runtime. bindings might help you there.
Yeah I just came across this walkthrough which somewhat outlines the "ugly" side of things 😛.
Native modules are a pain, but I might keep at it and see where I can get to (or see if the native module can be reimplemented in "plain ol' JavaScript", but somehow I don't expect it to be possible.
I've been playing around with the easy way and got this far:
electron-rebuild generated a binary output
My extension still failed as the path was not matching the generated output
Modified the folder of the generated output and it worked
So - I now have a "working" native node package running in a VSCode extension. But I was curious as to why it wanted a folder of node-v46... to load the binary. It seems that the logic to load the binary uses the node-gyp build/versioning lookup which might be somewhat broken in VSCode. The failure is that internally it does some checks to whether it's node, node-wekbit or electron, but process.versions.electron is undefined in the VSCode plugin. My guess is that because the extension is running out-of-process it's not getting that passed through, which in turn makes it a little unhappy.
Anyway I can at least get the extension launched, so chalk that up to success number 1 😁.
I've hit another problem that I'm not sure if it's related to it being a native module or if it's another bug, the native module is being reported as not found by VSCode's editor and the TypeScript compiler (when running the package step).
If I run from the debugger it works just fine, the native module is loaded, executed, etc, so I know it's there, but tsc doesn't seem to locate it. I think it's a TypeScript issue than a VSCode issue, but I can't find any info on it. Is it known at the VSCode end?
You must always compile it against the version of Electron that VSCode depends on, considering the VSCode version you're targeting. So, for VSCode 0.10.3 it is Electron 0.34.1.
Yeah I found that out, I'm just trying to avoid shipping a precompiled version of serialport and instead compile it as an install step, but I need to work out what version of VSCode is running (and that tells me what version of Electron)
Very tricky and it's exactly the reason why we haven't tackled this yet: every user that would install your extension would need the build tooling installed in their system (VS, gcc, etc.).
Yeah that's a fair point, I guess shipping the compiled module in my extension is probably a good idea (or at least the binary) and get it done for each platform.
I might be able to make an assumption of the build tools (given that it's work working with microprocessors) but it's solid assumption.
Brent Mealhouse (@bmealhouse) Finally got a chance to take a look at prebuildify. The problem I have is that my extension module is not native per se, but it depends on a couple of native modules. I'm not sure how to use prebuildify in that context. Ideally I would like to deliver my module with the prebuilt versions of those modules (which, as far as I understand, do not come with prebuilt binaries).
Anybody has experience on the matter ? Thanks.
I'm running into this issue currently. In particular, I'm trying to use nodegit which has a native dependency on libgit2. At first I was seeing some NODE_MODULE_VERSION mismatch errors. Those were resolved by downgrading my node version to 15.x.
But now I'm seeing an error:
Module did not self-register: '/Users/skainswo/dev/cuddlefish/vscode-extension/node_modules/nodegit/build/Release/nodegit.node'..
Is there a plan for a more robust native dependency solution for VSCode extensions?
Activity
aaronpowell commentedon Nov 26, 2015
I'm doing some more investigation on this to see if I can unblock myself by getting an
ia32version of the module loaded, so I installed thex86version of node.js, installed the native module (which in turned got the right binary).Now I get the following error:
Are native modules not supported in extensions?
joaomoreno commentedon Nov 26, 2015
The good: Nothing really.
The bad: Code extensions unfortunately don't support native extensions.
The ugly: There is a workaround. Bear with me:
npm_config_disturl=https://atom.io/download/atom-shellnpm_config_target=whatever value is there onelectronVersionnpm_config_arch=whatever the bit architecture you needHOME=something other that~, like~/.electron-gyp, so node-gyp and npm don't confuse themselves.win32-ia32,darwin,linux-ia32andlinux-x64. It would then dynamically require the correct binary for the running platform at runtime. bindings might help you there.aaronpowell commentedon Nov 26, 2015
Yeah I just came across this walkthrough which somewhat outlines the "ugly" side of things 😛.
Native modules are a pain, but I might keep at it and see where I can get to (or see if the native module can be reimplemented in "plain ol' JavaScript", but somehow I don't expect it to be possible.
joaomoreno commentedon Nov 26, 2015
We use the npm way in our build scripts, btw.
aaronpowell commentedon Nov 30, 2015
I've been playing around with the easy way and got this far:
electron-rebuildgenerated a binary outputSo - I now have a "working" native node package running in a VSCode extension. But I was curious as to why it wanted a folder of
node-v46...to load the binary. It seems that the logic to load the binary uses thenode-gypbuild/versioning lookup which might be somewhat broken in VSCode. The failure is that internally it does some checks to whether it's node, node-wekbit or electron, butprocess.versions.electronis undefined in the VSCode plugin. My guess is that because the extension is running out-of-process it's not getting that passed through, which in turn makes it a little unhappy.Anyway I can at least get the extension launched, so chalk that up to success number 1 😁.
aaronpowell commentedon Dec 1, 2015
I've hit another problem that I'm not sure if it's related to it being a native module or if it's another bug, the native module is being reported as not found by VSCode's editor and the TypeScript compiler (when running the
packagestep).If I run from the debugger it works just fine, the native module is loaded, executed, etc, so I know it's there, but
tscdoesn't seem to locate it. I think it's a TypeScript issue than a VSCode issue, but I can't find any info on it. Is it known at the VSCode end?joaomoreno commentedon Dec 1, 2015
It seems that you just need TypeScript typings to go along your native module. Try placing a file in your extension similar to this:
mylib.d.tsThen, both VSCode and TypeScript would drop the errors when you'd import the module:
aaronpowell commentedon Dec 2, 2015
ah, I didn't realise you need to have everything with a
.d.ts. All sorted and now it's on the marketplace - https://marketplace.visualstudio.com/items/aaronpowell.vscode-espruino (although I'm not sure it'll be installable for anyone else yet).Is there any way (easy or ugly) to work out the version of Electron when installing a plugin?
joaomoreno commentedon Dec 2, 2015
You must always compile it against the version of Electron that VSCode depends on, considering the VSCode version you're targeting. So, for VSCode 0.10.3 it is Electron 0.34.1.
aaronpowell commentedon Dec 2, 2015
Yeah I found that out, I'm just trying to avoid shipping a precompiled version of
serialportand instead compile it as an install step, but I need to work out what version of VSCode is running (and that tells me what version of Electron)joaomoreno commentedon Dec 3, 2015
Very tricky and it's exactly the reason why we haven't tackled this yet: every user that would install your extension would need the build tooling installed in their system (VS, gcc, etc.).
aaronpowell commentedon Dec 3, 2015
Yeah that's a fair point, I guess shipping the compiled module in my extension is probably a good idea (or at least the binary) and get it done for each platform.
I might be able to make an assumption of the build tools (given that it's work working with microprocessors) but it's solid assumption.
28 remaining items
pythoulon commentedon May 12, 2021
Brent Mealhouse (@bmealhouse) Finally got a chance to take a look at prebuildify. The problem I have is that my extension module is not native per se, but it depends on a couple of native modules. I'm not sure how to use prebuildify in that context. Ideally I would like to deliver my module with the prebuilt versions of those modules (which, as far as I understand, do not come with prebuilt binaries).
Anybody has experience on the matter ? Thanks.
bmealhouse commentedon May 15, 2021
pythoulon - You could fork those native modules and prebuildify them for VS code.
pythoulon commentedon May 17, 2021
Brent Mealhouse (@bmealhouse) Thanks for the hint. Hadn't thought of it... Will try that.
samuela commentedon Oct 17, 2021
I'm running into this issue currently. In particular, I'm trying to use nodegit which has a native dependency on libgit2. At first I was seeing some
NODE_MODULE_VERSIONmismatch errors. Those were resolved by downgrading my node version to 15.x.But now I'm seeing an error:
Is there a plan for a more robust native dependency solution for VSCode extensions?
Chore: Add node-pty
Chore: Add node-pty
Fix: Use dynamic imports for node-pty
Chore: Add node-pty
Fix: Use dynamic imports for node-pty
Chore: Add node-pty
Fix: Use dynamic imports for node-pty
Chore: Add node-pty
Fix: Use dynamic imports for node-pty