microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
161.78k stars 28.44k forks source link

Native node modules from extensions #658

Open aaronpowell opened 8 years ago

aaronpowell commented 8 years ago

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:

Otherwise I fear that my extension might be dead in the water :frowning:

aaronpowell commented 8 years ago

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).

Now I get the following error:

native-module-error

Are native modules not supported in extensions?

joaomoreno commented 8 years ago

The good: Nothing really. The bad: Code extensions unfortunately don't support native extensions. The ugly: There is a workaround. Bear with me:

aaronpowell commented 8 years ago

Yeah I just came across this walkthrough which somewhat outlines the "ugly" side of things :stuck_out_tongue:.

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 commented 8 years ago

We use the npm way in our build scripts, btw.

aaronpowell commented 8 years ago

I've been playing around with the easy way and got this far:

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 :grin:.

aaronpowell commented 8 years ago

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?

joaomoreno commented 8 years ago

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.ts

declare module 'mylib' {
    export function foo(arg: number): void;
}

Then, both VSCode and TypeScript would drop the errors when you'd import the module:

import * as mylib from 'mylib';
aaronpowell commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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)

joaomoreno commented 8 years ago

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 commented 8 years ago

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.

mateodelnorte commented 8 years ago

Is there a mechanism for downloading precompiled binaries as part of the build process, such that extension creators could use a tool to pre-compile an array binaries for different platform and node version targets - and the build process would bring down the appropriate binary and link it?

joaomoreno commented 8 years ago

node-pre-gyp exists for that purpose when dealing with node modules. But upon installation, we don't call npm install on an extension.

Tyriar commented 8 years ago

So Atom's apm 1.10 beta seems to ship with node and npm now, likely to avoid these exact issues http://blog.atom.io/2016/08/01/atom-1-9-and-1-10-beta.html

joaomoreno commented 8 years ago

Yep... it's starting to feel inevitable by now.

aaronpowell commented 8 years ago

I haven't done much with this for a while but my current thinking is that instead of trying to load the native module within the electron shell I think it'll be better to use spawn and uxe the native module from the default node.js install (which obviously requires there to be a node.js install).

I'm thinking this because it seems that the electron-rebuild module no longer works on Windows or with the version of electron being used.

RLovelett commented 8 years ago

Is there anyway to see the error messages upon faulty loading?

I am trying to make a language server that makes use of a native module. I've followed the steps outlined here and here and have arrived at a module that can be loaded from the extension. So far so good.

However, when my extension starts the server that tries to reference the same native module I get "The Swift server crashed 5 times in the last 3 minutes. The server will not be restarted."

This does not exactly give me a lot to go on to try and resolve where it is going wrong. And the process is dead before I have a chance to attach a debugger to it. If I could just get some messaging about what/why the server is dying that may help me crack the case.

aaronpowell commented 8 years ago

@RLovelett the problem is now that the version of Electron used in VSCode is a bit out of date (0.37.6 in the insider build of 2016-08-17 that I'm running). It seems that electron-rebuild no longer works with that version (the problem is with nslog dependency) and I'm not sure if it's being maintained.

This is why, for me, I'm thinking of running node in a separate process and passing messages back and forth so I can use a "standard" version of node, rather than the forked version used by electron. Not sure if that'd work in your scenario though.

TomasHubelbauer commented 6 years ago

Is this thread still up to date or have things changed since 2016? I see the mention of Atom shipping with Node and NPM, has VS Code started doing the same or is depending on native modules still cumbersome?

ncannasse commented 5 years ago

I'm maintaining a debugger which requires several native libraries. It requires me to push a new version everytime VSCode updates its Electron runtime (which 1.29 did again, from 2.0.5 to 2.0.12, which was preventing my precompiled extensions to load).

This is far from ideal, and while I understand this only concern a few extensions, maybe there should be a standard way to trigger an installation script so we can deal with it ourselves?

octref commented 5 years ago

While I can't promise adding any support to make it easier to use native modules, we can add some documentations for the current state: https://github.com/Microsoft/vscode-docs/issues/2211

akbyrd commented 5 years ago

Documentation would be great. This is definitely a nasty corner case to figure out for newcomers.

firien commented 5 years ago

The Extension Publishing section of Roadmap 2019 includes:

:runner: Enable extensions to install additional platform specific components at extension installation time.

would this address this issue?

JohnZ622 commented 5 years ago

I recently tried compiling a Node.js native extension, Edge.JS. VSCode version was 1.36.1. Node.JS version inside VSCode was 10.11.0. I built edge.js from src using node.exe 10.11.0 for target node version 10.11.0. Edge.js native extension is used in a "hello world" type vscode extension. VSCode Extension Host could not load my built edge.js bits. The error was " not a valid Win32 Application". Any help would be greatly appreciated, thanks.

pythoulon commented 4 years ago

Has any progress been made on the subject ? I have an extension that communicate over Bluetooth communication with an IoT device, using the @abandonware/noble module, which partly relies on native modules. Everything works fine in the debug extension host, because I can npm install everything, which will take care of compiling the native modules, but no such thing occurs when installing the extension from the marketplace in a plain VS Code session. If I wanted to explicitely provide the pre-compiled modules, how would I do that with my extension package ? Any help appreciated. Thanks.

dlech commented 4 years ago

Regarding Bluetooth low energy specifically, I wonder if it could be possible to use Web Bluetooth via a webview (probably worth opening a new issue for that).

XiaoningLiu commented 4 years ago

Any updates for this?

ncannasse commented 4 years ago

I switched my native dependencies such as ffi to ffi-napi which uses NodeJS API, which seems to be forward compatible so new electron versions no longer breaks the plugin.

meakbiyik commented 3 years ago

I am also dealing with this issue, and there is one thing I do not quite understand why: wouldn't it be easy and perfectly acceptable for vscode to just rebuild all extensions while installing using

npm rebuild --nodedir=/path/to/electron/vendor/node

just as recommended in https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md, as this command would do nothing for packages without native node modules, and fix all the issues with the others? I believe it is natural to expect for vscode to fix the node dependency issues since it does not provide access for electron's node to the extension developers, so it should act as a black box.

ganezdragon commented 3 years ago

hi moderators,

I could rebuild locally and test out my extension. But if I pack and publish it, it doesn't work in the client's machine. Please do let me know if you guys have any solution for publishing.

Thanks!

pythoulon commented 3 years ago

@ganezdragon for what it's worth, I ask my users to go to the extension folder (~/.vscode/extensions/your-extensions-name-and-version on my Windows machine) after installation/updated, open a terminal there, and type npm install at the command prompt. This will fully rebuild the extension, including compiling the native parts. You have to redo this with every update, but so far it has worked for me every time. You just have to make sure the version of electron you reference tracks the Node.js ABI version, but if you can compile your extension locally, that is normally taken care of. Good luck...

ganezdragon commented 3 years ago

@pythoulon thanks for the approach. Yea then I would have to go with this, and hope the users have necessary gcc also to compile it. Or I would have to look at some web bindings (but that has its problem of its own). But thanks for the quick response pythoulon.

bmealhouse commented 3 years ago

@ganezdragon @pythoulon - Have either of you tried prebuilding your native node module with prebuildify and then including the binaries in the published npm package? You can use this approach to avoid making your users run npm install inside your extension folder. Make sure you are publishing prebuilds for all platforms and architectures that VS Code supports.

ganezdragon commented 3 years ago

@bmealhouse, nope I haven't tried it. Let me try it out today and see how that works! Much thanks for telling us about the library.

pythoulon commented 3 years ago

@bmealhouse Will try it as soon as I get a chance. @ganezdragon please report here on your experience, if you can... Thanks.

pythoulon commented 3 years ago

@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 commented 3 years ago

@pythoulon - You could fork those native modules and prebuildify them for VS code.

pythoulon commented 3 years ago

@bmealhouse Thanks for the hint. Hadn't thought of it... Will try that.

samuela commented 2 years ago

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?

ghost commented 2 years ago

I need help implementing this in a sane manner over at vscode-textmate-languageservice. For some reason, even vscode-test and the getCoreNodeModule snippet refuse to work.

Found C:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\.vscode-test\vscode-winchive-1.62.1. Skipping download.

Warning: 'xshm' is not in the list of known options, but still passed to Electron/Chromium.

[main 2021-11-10T20:33:21.524Z] update#setState idle

Starting extension host with pid 22420.

[LocalProcessExtensionHost]: IExtensionHostStarter.start() took 30 ms.

Error: \\?\c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_modules\onigubuild\Release\onig_scanner.node is not a valid Win32 application.
\\?\c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_modules\oniguruma\buelease\onig_scanner.node
        at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1846)
        at Object.Module._extensions..node (internal/modules/cjs/loader.js:1185:18)
        at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1846)
        at Module.load (internal/modules/cjs/loader.js:982:32)
        at Module._load (internal/modules/cjs/loader.js:823:14)
        at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
        at Function.n._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:28606)
        at Function.b._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:25193)
        at Function.h._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:60406)
        at Module.require (internal/modules/cjs/loader.js:1006:19)
        at Module.require (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\.v-test\vscode-win32-archive-1.62.1\resources\app\extensions\microsoft-authentication\dist\extension.js:1:38399)
        at require (internal/modules/cjs/helpers.js:88:18)
        at Object.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice_modules\oniguruma\src\oniguruma.js:3:21)
        at Module._compile (internal/modules/cjs/loader.js:1125:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
        at Module.load (internal/modules/cjs/loader.js:982:32)
        at Module._load (internal/modules/cjs/loader.js:823:14)
        at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
        at Function.n._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:28606)
        at Function.b._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:25193)
        at Function.h._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:60406)
        at Module.require (internal/modules/cjs/loader.js:1006:19)
        at Module.require (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\.v-test\vscode-win32-archive-1.62.1\resources\app\extensions\microsoft-authentication\dist\extension.js:1:38399)
        at require (internal/modules/cjs/helpers.js:88:18)
        at Object.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice_modules\first-mate\lib\grammar.js:10:10)
        at Object.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice_modules\first-mate\lib\grammar.js:395:4)
        at Module._compile (internal/modules/cjs/loader.js:1125:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
        at Module.load (internal/modules/cjs/loader.js:982:32)
        at Module._load (internal/modules/cjs/loader.js:823:14)
        at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
        at Function.n._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:28606)
        at Function.b._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:25193)
        at Function.h._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:60406)
        at Module.require (internal/modules/cjs/loader.js:1006:19)
        at Module.require (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\.v-test\vscode-win32-archive-1.62.1\resources\app\extensions\microsoft-authentication\dist\extension.js:1:38399)
        at require (internal/modules/cjs/helpers.js:88:18)
        at Object.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice_modules\first-mate\lib\grammar-registry.js:12:13)
        at Object.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice_modules\first-mate\lib\grammar-registry.js:273:4)
        at Module._compile (internal/modules/cjs/loader.js:1125:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
        at Module.load (internal/modules/cjs/loader.js:982:32)
        at Module._load (internal/modules/cjs/loader.js:823:14)
        at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
        at Function.n._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:28606)
        at Function.b._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:25193)
        at Function.h._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:60406)
        at Module.require (internal/modules/cjs/loader.js:1006:19)
        at Module.require (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\.v-test\vscode-win32-archive-1.62.1\resources\app\extensions\microsoft-authentication\dist\extension.js:1:38399)
        at require (internal/modules/cjs/helpers.js:88:18)
        at Object.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice_modules\first-mate\lib\first-mate.js:4:22)
        at Object.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice_modules\first-mate\lib\first-mate.js:14:4)
        at Module._compile (internal/modules/cjs/loader.js:1125:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
        at Module.load (internal/modules/cjs/loader.js:982:32)
        at Module._load (internal/modules/cjs/loader.js:823:14)
        at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
        at Function.n._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:28606)
        at Function.b._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:25193)
        at Function.h._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:60406)
        at Module.require (internal/modules/cjs/loader.js:1006:19)
        at Module.require (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\.v-test\vscode-win32-archive-1.62.1\resources\app\extensions\microsoft-authentication\dist\extension.js:1:38399)
        at require (internal/modules/cjs/helpers.js:88:18)
        at Object.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservic\src\textmateEngine.js:18:22)
        at Module._compile (internal/modules/cjs/loader.js:1125:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
        at Module.load (internal/modules/cjs/loader.js:982:32)
        at Module._load (internal/modules/cjs/loader.js:823:14)
        at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
        at Function.n._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:28606)
        at Function.b._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:25193)
        at Function.h._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:60406)
        at Module.require (internal/modules/cjs/loader.js:1006:19)
        at Module.require (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\.v-test\vscode-win32-archive-1.62.1\resources\app\extensions\microsoft-authentication\dist\extension.js:1:38399)
        at require (internal/modules/cjs/helpers.js:88:18)
        at Object.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservic\test\suite\documentSymbolProvider.test.js:18:26)
        at Module._compile (internal/modules/cjs/loader.js:1125:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
        at Module.load (internal/modules/cjs/loader.js:982:32)
        at Module._load (internal/modules/cjs/loader.js:823:14)
        at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
        at Function.n._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:28606)
        at Function.b._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:113:25193)
        at Function.h._load (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\de-test\vscode-win32-archive-1.62.1\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:60406)
        at Module.require (internal/modules/cjs/loader.js:1006:19)
        at Module.require (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\.v-test\vscode-win32-archive-1.62.1\resources\app\extensions\microsoft-authentication\dist\extension.js:1:38399)
        at require (internal/modules/cjs/helpers.js:88:18)
        at c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_modules\mochamocha.js:430:36
        at Array.forEach (<anonymous>)
        at Mocha.loadFiles (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\nodules\mocha\lib\mocha.js:427:14)
        at Mocha.run (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_mo\mocha\lib\mocha.js:1028:10)
        at c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\out\test\suite\ind:24:23
        at f (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_modules\once.js:25:25)
        at Glob.<anonymous> (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\modules\glob\glob.js:148:7)
        at Glob.emit (events.js:315:20)
        at Glob._finish (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\nodeles\glob\glob.js:194:8)
        at done (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_modules\glob.js:179:14)
        at Glob._processGlobStar2 (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languagese\node_modules\glob\glob.js:634:12)
        at c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_modules\glob\js:623:10
        at RES (c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_modules\ght\inflight.js:31:16)

Error: \\?\c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_modules\onigubuild\Release\onig_scanner.node is not a valid Win32 application.
\\?\c:\Users\Public\Documents\Code\vscode-textmate-languageservice\test\vscode-matlab\node_modules\vscode-textmate-languageservice\node_modules\oniguruma\buelease\onig_scanner.node
[main 2021-11-10T20:33:31.082Z] Sending IPC message to channel 'vscode:electron-main->shared-process=exit' for shared process window that is destroyed      

Exit code:   1
Done

Failed to run tests
ghost commented 2 years ago

I found a solution mostly written by MS devs:

'use strict';

import vscode from 'vscode';

/**
 * Returns a node module installed with VSCode, or undefined if it fails.
 */
export default function<T>(id: string): T | null {
    try {
      return require(`${vscode.env.appRoot}/node_modules.asar/${id}`);
    } catch (err) {
        // ignore
    }

    try {
      return require(`${vscode.env.appRoot}/node_modules/${id}`);
    } catch (err) {
        // ignore
    }

    return null;
}