How can I use the get-port package from a VS Code extension? I was able to use get-port
in a standalone typescript
sample project here, but when I try to use the same tsconfig.json
with a VS Code extension I get the following error in the developer extension host log file:
[2022-04-19 15:42:18.314] [exthost] [error] Activating extension undefined_publisher.vscode-test-getport failed due to an error:
[2022-04-19 15:42:18.314] [exthost] [error] Error [ERR_REQUIRE_ESM]: require() of ES Module /home/hakon/test/vscode/vscode-test-getport/out/extension.js from /usr/share/code/resources/app/out/vs/loader.js not supported.
Instead change the require of extension.js in /usr/share/code/resources/app/out/vs/loader.js to a dynamic import() which is available in all CommonJS modules.
at Function.<anonymous> (node:electron/js2c/asar_bundle:5:13331)
at Function.<anonymous> (/usr/share/code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:104:32156)
The code can be found in the tsconfig
branch here. The above failure happens when I execute the command "View Port" which the extension contributes.
The code uses the following tsconfig.json
:
{
"compilerOptions": {
"module": "es6",
"target": "es6",
"outDir": "out",
"moduleResolution": "node",
"lib": [
"ES2020"
],
"sourceMap": true,
"rootDir": "src",
"strict": true
}
}
I first tried the original tsconfig.json
that comes with the yo code
generated "Hello world" template (see the main branch):
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2020",
"outDir": "out",
"lib": [
"ES2020"
],
"sourceMap": true,
"rootDir": "src",
"strict": true
}
}
which fails at activation (not when executing the "Show Port" command as the first example above did):
Activating extension 'undefined_publisher.vscode-test-getport' failed: require() of ES Module /home/hakon/test/vscode/vscode-test-getport/out/extension.js from /usr/share/code/resources/app/out/vs/loader.js not supported.
Instead change the require of extension.js in /usr/share/code/resources/app/out/vs/loader.js to a dynamic import() which is available in all CommonJS modules..
Any idea how I can fix this?