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 327 forks source link

Webpack warning #1355

Closed DoctorKrolic closed 11 months ago

DoctorKrolic commented 11 months ago

I'm trying to pack a VS Code extension using webpack. I am on the latest public version of vscode-languageclient and I'm getting this warning when I try to build the extension:

WARNING in ./node_modules/vscode-languageserver-types/lib/umd/main.js 3:24-31
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ./node_modules/vscode-languageserver-protocol/lib/common/api.js 23:13-51
 @ ./node_modules/vscode-languageserver-protocol/lib/node/main.js 24:13-37
 @ ./node_modules/vscode-languageclient/lib/common/client.js 9:41-82
 @ ./node_modules/vscode-languageclient/lib/node/main.js 27:17-44
 @ ./src/extension.ts 6:32-64 7:15-61

It it a known problem? It it even safe to use webpack in such case or it just generates less efficient code?

dbaeumer commented 11 months ago

@aeschli can you help me with this. It is caused by the changes you did to the UMD packaging and I see the same when trying to package my eslint extension.

aeschli commented 11 months ago

I think the problem is that webpack doesn't pick up the browser bits. Make sure to to have

resolve: {
            mainFields: ['browser', 'module', 'main'],
aeschli commented 11 months ago

I assumed you wanted to build a web extension.

If this is a desktop extension, it is

resolve: {
            conditionNames: ['import', 'require'],
            mainFields: ['module', 'main'],
dbaeumer commented 11 months ago

@aeschli Thanks. Your tips worked for me.

dbaeumer commented 11 months ago

@DoctorKrolic see @aeschli tips.

DoctorKrolic commented 11 months ago

Thanks for tips, the issue is resolved. However, since this required me to explicitly specify additional configuration parameters, I think there are steps that can be done to fully resolve this incident:

  1. Can code be changed on your end to avoid this? If you can just change some bits to avoid everyone else specifying additional webpack config parameters, this would be really cool
  2. If the first suggestion cannot be done for various reasons (and it is most likelt so), I think it would be benifitial to include this solution into documentation, e.g. create a section in the root README, where the issue and its solution are briefly described. This way you would avoid such questions in the future and make this info searchable via search engines and AI assistants, so people can discover this easily
aeschli commented 11 months ago

What change was needed?

DoctorKrolic commented 11 months ago

The latter one:

resolve: {
            conditionNames: ['import', 'require'],
            mainFields: ['module', 'main'],
TamiTakamiya commented 9 months ago

We also encountered this issue in our VS Code extension build and adding

resolve: {
            conditionNames: ['import', 'require'],
            mainFields: ['module', 'main'],

fixed the build issue. However, the extension now started showing another error at runtime:

crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported

We may be able to resolve this specific error, but I wonder if adding those parameters to resolve could have changed other behaviors as well.

dbaeumer commented 9 months ago

From what I read in https://github.com/uuidjs/uuid#getrandomvalues-not-supported this seems unrelated.

@aeschli any additional thoughts