-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Syntax error in Nuxt project due to graphql-js pull request #3887 #3919
Comments
I ran into the same problem with a React project. |
It looks like the code published by graphql is fine: https://unpkg.com/browse/[email protected]/jsutils/instanceOf.mjs And can be imported as is without any problems: So it almost feels like a bug in whatever is transpiling your project, which (judging from your screenshot) also looks like esbuild output. However, running the same code through esbuild again, doesn't result in the error for me: Do you know which esbuild configuration options your build process uses? And are there are tools that may transpile/compile your code? |
I ran into the same issue in a vite / vue / ts project after upgarding from I'm using node v18.14.0, yarn 1.22.19, vite 4.3.9, vue 3.3.4, typescript 5.1.3, vue-tsc 1.8.1, @esbuild-plugins/node-globals-polyfill 0.2.3, @esbuild-plugins/node-modules-polyfill 0.2.2, and many more ... The issue only appears if I run the application in dev mode. The production build works fine. 🤔 |
Are you sure the code is fine ? Shouldn't it be : _globalThis$(process.env.NODE_ENV) === 'production' ? ;) |
Yeah, I'm sure the code is fine. Why do you think it should be something else? |
Same here. The generated code is invalid, a |
Hey, I am using ViteJS and facing same problem. It looks like ViteJS/esbuild is replacing I am questioning if you are forced to use graphql-js/src/jsutils/instanceOf.ts Line 12 in d766c8e
The compiled output of ViteJS/esbuild should look like this: |
Aha, I see what you're saying. That makes sense indeed. I imported the module in a browser to check for syntax errors, and when I saw none I assumed that the code was correct, but didnt actually verify the logic. That would mean the issue is likely somewhere in the buildtooling that graphql uses internally. I try to see if I can figure out where exactly this is going wrong. |
@thepassle if you replace graphql-js/src/jsutils/instanceOf.ts Line 12 in d766c8e
against |
Fixes: #3919 #3920 #3921 Context: #3887 changed code and introced optinal chaining. `globalThis.process?.env.NODE_ENV` is transpiled into ``` (_globalThis$process = globalThis.process) === null || _globalThis$process === void 0 ? void 0 : _globalThis$process.env.NODE_ENV; ``` Bundlers incorrectly replace (probably RegExp) `process.env.NODE_ENV` with `"development"` resulting in: ``` (_globalThis$process = globalThis.process) === null || _globalThis$process === void 0 ? void 0 : _globalThis$"development"; ``` Technically it's not a graphql issue but an issue with bundler but since it caused so much pain in comutinity this is an attempt to fix it within our codebase.
@okaufmann It's an issue with Nuxt internals, but I added a workaround for it in |
It works now with ViteJS |
@razorness For that, you need to define |
@IvanGoncharov Thanks for the quick fix it does work perfectly again 🎉 |
Running into the same issue with quasar 2.12.2 / vite. Not sure if it is an issue if bundlers replace I created a very simple workarround: Just change
to
and everything works fine because nothing is replaced unexpectedly. For an instant fix you can run
manually or use this script
in your build-pipline. Don´t forget to delete the build-cache after patching the file, in my case |
Hacking node_module? It's not the best idea. |
The problem hits only Quasar. :( Vuertify3 which uses also Vite has no problem with that. import gql from "graphql-tag"; |
Imo this is a patch, not a hack. And perfectly fine to handle smaller bugs like this. Maybe quasar does not work like you would expect. Ok. In my current project, I replaced Nuxt / Vuetify / Apollo, a horrible combination by quasar / graphql-codegen. Yes, consider quasar as the answer to Nuxt / Vuetify but you are free to stick on your well-known solutions. |
Experiencing the same issue in a React 18 + Vite 4.1 project. Updating Vite to >=4.2 solves the issue regardless of the graphql version |
Hi
It looks like #3887 is causing problems in my Nuxt project. When compiled, there is a syntax error which breaks the app completely:
v16.6.0 works perfectly.
I cannot verify if this is only a problem when used with Nuxt or not.
The text was updated successfully, but these errors were encountered: