nginx / nginx/nginx-directive-reference

unable to use from a vscode language server extension

Open
#407 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
12
Forks
3
Avg merge
7h 59m
Merged PRs (30d)
4

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:

  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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the import from @nginx/reference-lib in the VS Code Extension Development Host, comparing it with the standalone tsc && node out/server.js run. Inspect the library's dist/index.js and the extension server's tsconfig.json and package.json; done means the extension host can import the library without the reported module-format errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.