microsoft / vscode-languageserver-node

Language server protocol implementation for VSCode. This allows implementing language services in JS/TS running on node.js
MIT License
1.46k stars 326 forks source link

Compiling my LanguageServer returns TS2792: Cannot find module 'vscode-languageclient/node' #902

Closed aboimpinto closed 2 years ago

aboimpinto commented 2 years ago

Hello guys,

I have this extension https://github.com/AvaloniaUI/Avalonia.VSCodeExtension

I can run perfectly locally but when I try to package, the svetle views aren't being included. After some investigation, looks like I have to use the WebPack to take everything in the scr folder.

I add the WebPack and WebPack-Cli, created entries in the package.json for the webpack and add a webpack.config.js as described here https://code.visualstudio.com/api/working-with-extensions/bundling-extension

When I run the command $ npm run webpack

I got this result:

> avalonia-vscode-extension@0.0.3 webpack
> webpack --mode development

asset extension.js 792 KiB [compared for emit] (name: main) 1 related asset
runtime modules 937 bytes 4 modules
modules by path ./node_modules/ 670 KiB 135 modules
modules by path ./src/*.ts 31.2 KiB
  ./src/extension.ts 2.32 KiB [built] [code generated] [1 error]
  ./src/AvaloniaNewProjectManager.ts 2.94 KiB [built] [code generated]
  ./src/AvaloniaProjectProvider.ts 1.28 KiB [built] [code generated]
  ./src/AvaloniaNewFileManager.ts 4.52 KiB [built] [code generated]
  ./src/CreateNewAppPanel.ts 5.41 KiB [built] [code generated]
  + 7 modules
+ 8 modules

ERROR in /home/esqueleto/myWork/Avalonia.VSCodeExtension/src/extension.ts
./src/extension.ts 11:7-35
[tsl] ERROR in /home/esqueleto/myWork/Avalonia.VSCodeExtension/src/extension.ts(11,8)
      TS2792: Cannot find module 'vscode-languageclient/node'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
ts-loader-default_4f8b3ed5ab8e20ee

ERROR in /home/esqueleto/myWork/Avalonia.VSCodeExtension/src/test/runTest.ts
3:25-48
[tsl] ERROR in /home/esqueleto/myWork/Avalonia.VSCodeExtension/src/test/runTest.ts(3,26)
      TS2792: Cannot find module '@vscode/test-electron'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
ts-loader-default_4f8b3ed5ab8e20ee

webpack 5.70.0 compiled with 2 errors in 1781 ms

after some investigation in the closed issued in this repository, I realise the command

$ vsce ls                                                                                                                                                                                                 1 ↵
Executing prepublish script 'npm run vscode:prepublish'...

> avalonia-vscode-extension@0.0.3 vscode:prepublish
> npm run compile

> avalonia-vscode-extension@0.0.3 compile
> tsc -p ./

node_modules/@types/eslint/index.d.ts:450:42 - error TS2724: '"/home/esqueleto/myWork/Avalonia.VSCodeExtension/node_modules/@types/estree/index"' has no exported member named 'ChainExpression'. Did you mean 'ThisExpression'?

450         ChainExpression?: ((node: ESTree.ChainExpression & NodeParentExtension) => void) | undefined;
                                             ~~~~~~~~~~~~~~~

node_modules/@types/eslint/index.d.ts:473:43 - error TS2694: Namespace '"/home/esqueleto/myWork/Avalonia.VSCodeExtension/node_modules/@types/estree/index"' has no exported member 'ImportExpression'.

473         ImportExpression?: ((node: ESTree.ImportExpression & NodeParentExtension) => void) | undefined;
                                              ~~~~~~~~~~~~~~~~

Found 2 errors.

 ERROR  npm failed with exit code 2

I'm confused. Is this a problem regarding the component vscode-languagerclient/node or some problem with the node_modules?

I have no idea how to solve one or another.

Can anyone help me? Thanks in advance Paulo Aboim Pinto

dbaeumer commented 2 years ago

In general you need to package (webpack) the client and server independently. You might want to look at this repository on how to do this: https://github.com/microsoft/vscode-eslint

When you webpack the extension side you should exclude the tests or have the test in a separate folder.

I will close the issue since there is IMO no action required. You can still add comments so we can continue the discussion.

aboimpinto commented 2 years ago

Thanks for the answer ...

what I did already:

still don't know why I have the error

$ npm run webpack                      

> avalonia-vscode-extension@0.0.3 webpack
> webpack --mode development

asset extension.js 792 KiB [compared for emit] (name: main) 1 related asset
runtime modules 937 bytes 4 modules
modules by path ./node_modules/ 670 KiB 135 modules
modules by path ./src/*.ts 31.2 KiB
  ./src/extension.ts 2.32 KiB [built] [code generated] [1 error]
  ./src/AvaloniaNewProjectManager.ts 2.94 KiB [built] [code generated]
  ./src/AvaloniaProjectProvider.ts 1.28 KiB [built] [code generated]
  ./src/AvaloniaNewFileManager.ts 4.52 KiB [built] [code generated]
  ./src/CreateNewAppPanel.ts 5.41 KiB [built] [code generated]
  + 7 modules
+ 8 modules

ERROR in /home/esqueleto/myWork/Avalonia.VSCodeExtension/src/extension.ts
./src/extension.ts 11:7-35
[tsl] ERROR in /home/esqueleto/myWork/Avalonia.VSCodeExtension/src/extension.ts(11,8)
      TS2792: Cannot find module 'vscode-languageclient/node'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
ts-loader-default_4f8b3ed5ab8e20ee

webpack 5.70.0 compiled with 1 error in 1762 ms

when I do

$ vsce ls | grep vscode-languageclient/node                                                                                                                                                               
node_modules/vscode-languageclient/node.cmd
node_modules/vscode-languageclient/node.js

It's missing anything?

dbaeumer commented 2 years ago

I actually have no idea. The file it should include is node_modules/vscode-languageclient/node.js which is obviously there. My guess is some configuration missing / wrong in the webpack config. But it is simply a guess.

sdankel commented 2 years ago

I'm facing this issue as well. The language client code is in a separate package and is imported in package.json. This error occurs when I set "module": "esnext" in tsconfig. Using "module": "NodeNext" or "module": "node16" the error goes away.

However, I want to use features from esnext. Can we reopen this issue until it's solved?

dbaeumer commented 2 years ago

The libraries have not been tested with esnext module loading. I recommend that you open a new issue and request support for that mode.