Skip to content
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

graphql-js v16.7.0 breaks the compilation of SvelteKit #3920

Closed
huth-pesser opened this issue Jun 22, 2023 · 7 comments
Closed

graphql-js v16.7.0 breaks the compilation of SvelteKit #3920

huth-pesser opened this issue Jun 22, 2023 · 7 comments

Comments

@huth-pesser
Copy link

I use graphql-js in a webapp using SvelteKit. After updating from version 16.6.0 to version 16.7.0 my app does not work anymore.

As far as I analyzed this correctly, the problem seems to be the change in src/jsutils/instanceOf.ts

from

  process.env.NODE_ENV === 'production'

to

  globalThis.process?.env.NODE_ENV === 'production'

SvelteKit seems to replace env.NODE_ENV by the string "development" or "production" on compiling the sources and that ends up in the following invalid code

var instanceOf = (
  /* c8 ignore next 6 */
  // FIXME: https://github.com/graphql/graphql-js/issues/2317
  ((_globalThis$process = globalThis.process) === null || _globalThis$process === void 0 ? void 0 : _globalThis$"development") === "production" ? function instanceOf2(value, constructor) {
...

the old version of instanceOf lead to this code

var instanceOf = (
  /* c8 ignore next 6 */
  // FIXME: https://github.com/graphql/graphql-js/issues/2317
  // eslint-disable-next-line no-undef
  false ? function instanceOf2(value, constructor) {
...

I don't know why this change was made so unfortunatly I don't really know how to fix this the best way. In my opionen it would by nice, if this part could be reversed to this old implementation.

@racc-oo-n
Copy link

I have the same error using vitejs

@huth-pesser
Copy link
Author

Since I use SvelteKit with Vite, it could be a problem in conjunction with Vite and not SvelteKit.

@racc-oo-n
Copy link

vitejs/vite#13597

I think there is a solution to our problem 😄

@ryota-murakami
Copy link

It's also happen with React.
Screenshot 2023-06-22 at 22 50 49

IvanGoncharov added a commit that referenced this issue Jun 22, 2023
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.
@IvanGoncharov
Copy link
Member

@docseltsam It's an issue with SvetleKit internals, but I added a workaround for it in 16.7.1 Can you please confirm that it is fixed?

@vhatsura
Copy link

I can confirm that the workaround added into 16.7.1 resolves the issue with Vite

@huth-pesser
Copy link
Author

I can also confirm that the workaround in 16.7.1solves the issue with my app. Thank you very much for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants