Skip to content

unable to use from a vscode language server extension #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ryepup opened this issue May 5, 2025 · 0 comments
Open

unable to use from a vscode language server extension #407

ryepup opened this issue May 5, 2025 · 0 comments

Comments

@ryepup
Copy link
Collaborator

ryepup commented May 5, 2025

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:

  1. 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)
  2. npm install --save @nginx/reference-lib in the "server" part of the extension
  3. add a import { find } from '@nginx/reference-lib'
  4. run the server by itself, should work fine via tsc && node out/server.js
  5. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant