Description
Describe the bug
Something about the bundling process isn't working right, and I don't know enough about npm/typescript packaging to be clear and concise.
To reproduce
Steps to reproduce the behavior:
- follow https://code.visualstudio.com/api/language-extensions/language-server-extension-guide to make a stub language server in typescript that you can debug in a new VScode instance (aka Extension Development Host)
npm install --save @nginx/reference-lib
in the "server" part of the extension- add a
import { find } from '@nginx/reference-lib'
- run the server by itself, should work fine via
tsc && node out/server.js
- run the server inside the extension dev host, get an error:
Uncaught Error Error: require() of ES Module .../server/node_modules/@nginx/reference-lib/dist/index.js from .../server/out/server.js not supported.
Futzing around with various arcane tsconfig.json
or package.json
settings could get different errors, like
Uncaught ReferenceError ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and '...server/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
or
Uncaught Error Error: Cannot find module '.../server/node_modules/vscode-languageserver/node' imported from .../server/out/server.js Did you mean to import "vscode-languageserver/node.js"?
Expected behavior
Extension dev host can import the library.
Your environment
- node 23.11
- macos
Additional context
Asking AI didn't really help. It just repeatedly told me to set things in json files that I already had, or suggested that the lib needed to be published differently to supports modules and commonjs, but all this packaging stuff is not my area of expertise.