-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Handling vscode-languageserver with NMR #3469
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
Handling vscode-languageserver with NMR #3469
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MrSnix I really value your contributions. thank you! this was bugging me too, just hadn't had the time+headspace to look into it. Thanks for writing up your process. |
@MrSnix I'd be kinda curious if it's possibly to easily close the loop on this (and remove the need for us to add another loader) in the future. It appears according to microsoft/vscode-languageserver-node#303 (comment) that vscode-languageserver-node have allowed ES Modules for a few years now. I wonder what change would be required to get that version into our build. I think maybe it'd be a change in |
Just to see... I tried updating graphql to v15.5.1 to see if it makes the error go away, and it didn't. @MrSnix did you ever get a chance to take a look (no pressure whatsoever! just curious if you had any thoughts 😄)? |
Reopening this because it seemed to have been closed in error with #3926 😅 |
Hi @develohpanda and @dimitropoulos, I apologize for the late answer on this one 😭 . The 3rd solution Is it what you were looking for @dimitropoulos 😃 ? Changes:
|
that's certainly an improvement! I'll take it (don't get me wrong!) but what I was thinking about was fixing this in the upstream such that no changes other than updating a dependency in our package.json(s) would be needed to get this error to go away. it seems like this could be a change that needs to be made to I'll take a look at this again tomorrow, but as far as I'm concerned this is pretty much ready to merge. Can't have our cake and eat it too. Still might be cool to look into the upstream to see why this is happening. |
Okay @dimitropoulos , let's sort this out 😎 !
If I am not wrong, the main issue is related to the entry point specified by Here you can see it: vscode-languageserver-types - package.json - L15 {
"main": "./lib/umd/main.js",
"typings": "./lib/umd/main"
}
We may ask for changing the entry point 🧐 but I don't think authors are willing to do it 😬 as they already stated in another thread.
This is a quote from: compile types package to commonjs module The proposed solution inside those threads is the What do you think ? Thanks |
The reason that
So, to recap, you're totally right about this, but it looks like we're both talking different npms. What I'm sayin' is I think we can fix the problem higher up the dependency tree at the level of the graphql dependencies. While lookin around I found something very interesting - https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-interface seems to have an esm version (notice, Looking further up their monorepo, it seems like they're going with esm for everything, 2 years ago they made a commit graphql/graphiql@34101c8 which I only saw because it's the most recent change to their monorepo's root tsconfig. I'm still looking into it, but maybe we can just change how we consume Normally I'd look for that and wait to post this comment, but I can see that you are working on this now so I wanted to send this to you as I found it. I'm gonna spend a few more minutes on this and report back some time today one way or another what I find. by the way, the solution you found with |
ok, here's an idea, we may be able to tell TypeScript to just get the esmodule version (if it isn't already, and I feel like the fact that we're getting this error is evidence that it isn't, maybe?): https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping. Ok, so that just means adding to our tsonfig for insomnia-app. Shouldn't be so difficult, right? Well, haha.. apparently not so: I don't quite understand how, but the package.json of Thoughts? |
Another update: I can confirm that this error does indeed stem from If you remove those imports, the error goes away. import 'codemirror-graphql/hint';
import 'codemirror-graphql/lint';
import 'codemirror-graphql/info';
import 'codemirror-graphql/jump';
import 'codemirror-graphql/mode';
import 'codemirror-graphql/variables/lint';
import 'codemirror-graphql/variables/mode'; I tried changing these like this: import 'codemirror-graphql/hint.esm';
import 'codemirror-graphql/lint.esm';
import 'codemirror-graphql/info.esm';
import 'codemirror-graphql/jump.esm';
import 'codemirror-graphql/mode.esm';
import 'codemirror-graphql/variables/lint.esm';
import 'codemirror-graphql/variables/mode.esm'; and also like this import 'codemirror-graphql/hint.esm.js';
import 'codemirror-graphql/lint.esm.js';
import 'codemirror-graphql/info.esm.js';
import 'codemirror-graphql/jump.esm.js';
import 'codemirror-graphql/mode.esm.js';
import 'codemirror-graphql/variables/lint.esm.js';
import 'codemirror-graphql/variables/mode.esm.js'; and these didn't compile. Ok, so then I also tried adding "baseUrl": "./",
"paths": {
"codemirror-graphql/hint": ["codemirror-graphql/hint.esm"],
"codemirror-graphql/lint": ["codemirror-graphql/lint.esm"],
"codemirror-graphql/info": ["codemirror-graphql/info.esm"],
"codemirror-graphql/jump": ["codemirror-graphql/jump.esm"],
"codemirror-graphql/mode": ["codemirror-graphql/mode.esm"],
"codemirror-graphql/variables/lint": ["codemirror-graphql/variables/lint.esm"],
"codemirror-graphql/variables/mode": ["codemirror-graphql/variables/mode.esm"],
} to the So the three interesting pieces of information are:
|
I never dealt with an issue like this, so I'm really going blind on this one and I may say dumb things 😭 , be aware!
I agree with you 😄 , I think it's not using the right version 😢 . My unsuccessful attempt: The root cause
It uses the following snippet to load the File: var graphql_language_service_interface_1 = require("graphql-language-service-interface"); I assume <= this is the reason the umd version is loaded Meanwhile the esm version: File: import { getDiagnostics } from 'graphql-language-service-interface'; The idea Failed to compile, webpack
Considerations:
I don't know if my reasoning is right but my knowledge ends here 😢 and I don't think I can help more than that. EDIT: |
Another consideration about It seems not effective, I mean it seems like it doesn't do anything at all. "paths":` {
"codemirror-graphql/hint": ["codemirror-graphql/hint.esm"],
"codemirror-graphql/lint": ["codemirror-graphql/lint.esm"],
"codemirror-graphql/info": ["codemirror-graphql/info.esm"],
"codemirror-graphql/jump": ["codemirror-graphql/jump.esm"],
"codemirror-graphql/mode": ["codemirror-graphql/mode.esm"],
"codemirror-graphql/variables/lint": ["codemirror-graphql/variables/lint.esm"],
"codemirror-graphql/variables/mode": ["codemirror-graphql/variables/mode.esm"],
} In the warning message I still get this stack trace:
Meanwhile, I'd expect this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welp. I'm outta ideas for things we can do in our project. I learned a lot, so that's always cool, but I don't think it's worth the requisite time to really get this solved in the cleanest possible way for our own project.
I was moreso interested in better understanding this because I want to know if there's some issue in our build chain and this is just the first/only place that happens to surface an error. That doesn't seem to be the case - it looks like something specific to this one dependency (graphql-language-service-interface
) and how it imports vscode-languageserver-types
.
Not totally mandatory, but I think we should add a comment (https://github.com/Kong/insomnia/pull/3469/files#r692320932) linking back to this PR, should someone wonder in the future (or if this line is moved somewhere else and it gets hard to track the git history in the future) what this was all about.
@develohpanda what do you think?
Once we merge, I'll make an issue (unless @MrSnix you want to) on the graphql-language-service-interface
just to let them know about our use-case. Who knows, maybe they'll have a better solution. I searched their repo and didn't see anyone else that has reported this.
@dimitropoulos I was thinking that you may be right about the A lot of their modules have the Some examples:
About who should open the issue, I leave the choice to you or @develohpanda. EDIT: EDIT 2: NPM Registry: https://unpkg.com/browse/codemirror-graphql@1.0.2/ |
Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com>
@MrSnix great find! make an issue and show them what you found and let's see what they say. maybe that's the whole issue(?!?!)? |
@dimitropoulos I opened the issue, if necessary please feel free to add more context, I limited myself to describe and contextualize the bug without explaining the whole Webpack thing related to our warning: See the new issue here |
It looks like they go months without responding to issues. I think we should just merge this for now. @develohpanda if you agree, please merge. |
The problem:

While working on Insomnia, this warning message gets usually displayed every time the app is recompiled or simply reloaded.
Now, for the sake of it, I googled around to better understand if we can do something about it.
Webpack doesn't like the way the

require
function is used inside this specific package (vscode-languageserver-types
).Going deeper, Webpack doesn't like the UMD (Universal Module Definition) format, it gladly accepts commonJS, AMD and ESM but not UMD, the native format of the mentioned package. So he throws the warning.
Source: Webpack v4 Doc
The 1st solution:
Using
noParse
inside the configuration prevents webpack from parsing any files matching the given regular expression(s) and from throwing this annoying issue.vscode-languageserver-types
is recognised to be non-webpack friendly due to his format and it's harmless ignoring him. It won't change its behaviour at runtime.The 2nd solution
Another possible workaround is to deal with it using
umd-compat-loader
.This loader simply removes the UMD wrapper - effectively unwrapping it back to commonjs.
So, this PR ?:
I propose to fix this with the second approach, allowing webpack to statically extract the dependencies because I feel like it is more consistent instead of ignoring it ... but as always, every opinion is welcomed.
Proof:
No more warning is displayed.
Doc & Issue:
vscode-languageservice thread
Webpack - No parse