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

Bug in removeTemporaryGlobals in react-native #8754

Closed
doomsower opened this issue Sep 5, 2021 · 5 comments
Closed

Bug in removeTemporaryGlobals in react-native #8754

doomsower opened this issue Sep 5, 2021 · 5 comments

Comments

@doomsower
Copy link
Contributor

I'm upgrading my monorepo app (web, react-native) from apollo-client v2 to apollo-client v3. So far, upgrade went smooth for web apps and shared libraries. In react-native-app, however, I'm getting error you can see below in Actual outcome section.

I've checked source code of apollo-client here and it seems that this removeTemporaryGlobals is a workaround for graphql/graphql-js#2894. So I've commented out everything related to removeTemporaryGlobals and it seems to be working now. Maybe because I've locked my graphql version to 15.5.2 in yarn resolutions and graphql/graphql-js#3186 seems to be fixing the same bug in graphql@15.5.2.

diff --git a/node_modules/@apollo/client/utilities/globals/globals.cjs.js b/node_modules/@apollo/client/utilities/globals/globals.cjs.js
index 90fde69..92f64b7 100644
--- a/node_modules/@apollo/client/utilities/globals/globals.cjs.js
+++ b/node_modules/@apollo/client/utilities/globals/globals.cjs.js
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
 
 var tsInvariant = require('ts-invariant');
 var process$1 = require('ts-invariant/process');
-var graphql = require('graphql');
+// var graphql = require('graphql');
 
 function maybe(thunk) {
     try {
@@ -37,15 +37,15 @@ function getDEV() {
 }
 var DEV = getDEV();
 
-function removeTemporaryGlobals() {
-    graphql.isType(null);
-    return process$1.remove();
-}
+// function removeTemporaryGlobals() {
+//     graphql.isType(null);
+//     return process$1.remove();
+// }
 
 function checkDEV() {
     __DEV__ ? tsInvariant.invariant("boolean" === typeof DEV, DEV) : tsInvariant.invariant("boolean" === typeof DEV, 38);
 }
-removeTemporaryGlobals();
+// removeTemporaryGlobals();
 
 exports.InvariantError = tsInvariant.InvariantError;
 exports.invariant = tsInvariant.invariant;

Intended outcome:

App should at least build and start

Actual outcome:

I'm getting undefined is not a function error in globals.cjs.js (41:5)

function removeTemporaryGlobals() {
    graphql.isType(null);
    return process$1.remove();
}

How to reproduce the issue:

Versions

I guess npx envinfo@latest --preset apollo --clipboard is not returning everything it's supposed to return because of monore.

@apollo/client 3.4.10
graphql 15.5.2

System:
OS: macOS 11.5.1
Binaries:
Node: 14.17.4 - ~/.nvm/versions/node/v14.17.4/bin/node
Yarn: 1.22.11 - ~/.nvm/versions/node/v14.17.4/bin/yarn
npm: 7.20.3 - ~/.nvm/versions/node/v14.17.4/bin/npm
Browsers:
Chrome: 92.0.4515.159
Firefox: 91.0.2
Safari: 14.1.2

@benjamn
Copy link
Member

benjamn commented Sep 9, 2021

@doomsower What do you see if you run require("graphql").isType in your Node terminal?

% node
Welcome to Node.js v16.6.1.
Type ".help" for more information.
> require("graphql").isType
[Function: isType]
> require.resolve("graphql")
'/private/tmp/node_modules/graphql/index.js'

Possibly related: #8663 (comment)

@doomsower
Copy link
Contributor Author

@benjamn Same output both in monorepo root and in mobile app package dir:

Welcome to Node.js v14.17.6.
Type ".help" for more information.
> require("graphql").isType
[Function: isType]
> require.resolve("graphql")
'/Volumes/Projects/censored/node_modules/graphql/index.js'

Maybe this can be helpful. graphql is locked to 15.5.3 and @apollo/client to >=3.4.

npm ls graphql
@censored/root@0.0.147 /Volumes/Projects/censored
├─┬ @graphql-codegen/add@3.1.0
│ ├─┬ @graphql-codegen/plugin-helpers@2.1.1
│ │ └── graphql@15.5.3 deduped
│ └── graphql@15.5.3
├─┬ @graphql-codegen/cli@2.2.0
│ ├─┬ @graphql-codegen/core@2.1.0
│ │ ├─┬ @graphql-tools/schema@8.2.0
│ │ │ ├─┬ @graphql-tools/merge@8.1.2
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/apollo-engine-loader@7.1.0
│ │ └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/code-file-loader@7.1.0
│ │ ├─┬ @graphql-tools/graphql-tag-pluck@7.1.0
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/git-loader@7.1.0
│ │ ├─┬ @graphql-tools/graphql-tag-pluck@7.1.0
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/github-loader@7.1.0
│ │ ├─┬ @graphql-tools/graphql-tag-pluck@7.1.0
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/graphql-file-loader@7.1.0
│ │ ├─┬ @graphql-tools/import@6.4.0
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/json-file-loader@7.2.0
│ │ └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/load@7.3.0
│ │ └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/prisma-loader@7.1.0
│ │ ├─┬ graphql-request@3.5.0
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/url-loader@7.1.0
│ │ ├─┬ @graphql-tools/delegate@8.2.1
│ │ │ ├─┬ @graphql-tools/batch-execute@8.1.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/wrap@8.1.0
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @n1ru4l/graphql-live-query@0.7.1
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ graphql-ws@5.4.1
│ │ │ └── graphql@15.5.3 deduped
│ │ ├── graphql@15.5.3 deduped
│ │ └─┬ subscriptions-transport-ws@0.10.0 invalid: "^0.9.0" from node_modules/@apollo/client
│ │   └── graphql@15.5.3 deduped
│ ├─┬ @graphql-tools/utils@8.2.2
│ │ └── graphql@15.5.3 deduped
│ ├─┬ graphql-config@4.0.1
│ │ ├─┬ @graphql-tools/merge@6.2.17
│ │ │ ├─┬ @graphql-tools/utils@8.0.2
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ └── graphql@15.5.3 deduped
├─┬ @graphql-codegen/fragment-matcher@3.1.0
│ └── graphql@15.5.3 deduped
├─┬ @graphql-codegen/import-types-preset@2.1.3
│ ├─┬ @graphql-codegen/visitor-plugin-common@2.2.0
│ │ ├─┬ @graphql-tools/optimize@1.1.0
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/relay-operation-optimizer@6.4.0
│ │ │ ├── graphql@15.5.3 deduped
│ │ │ └─┬ relay-compiler@11.0.2
│ │ │   └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/utils@8.2.1
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ └── graphql@15.5.3 deduped
├─┬ @graphql-codegen/near-operation-file-preset@2.1.3
│ └── graphql@15.5.3 deduped
├─┬ @graphql-codegen/typescript-apollo-client-helpers@2.1.3
│ └── graphql@15.5.3 deduped
├─┬ @graphql-codegen/typescript-document-nodes@2.1.3
│ └── graphql@15.5.3 deduped
├─┬ @graphql-codegen/typescript-operations@2.1.3
│ └── graphql@15.5.3 deduped
├─┬ @graphql-codegen/typescript-react-apollo@3.1.3
│ ├─┬ graphql-tag@2.12.5
│ │ └── graphql@15.5.3 deduped
│ └── graphql@15.5.3 deduped
├─┬ @graphql-codegen/typescript-resolvers@2.2.0
│ └── graphql@15.5.3 deduped
├─┬ @graphql-codegen/typescript@2.2.1
│ └── graphql@15.5.3 deduped
├─┬ @censored/backend@0.0.482 -> ./packages/backend
│ ├─┬ apollo-server-errors@3.1.0
│ │ └── graphql@15.5.3 deduped
│ ├─┬ apollo-server-koa@3.3.0
│ │ ├─┬ apollo-server-core@3.3.0
│ │ │ ├─┬ @graphql-tools/mock@8.3.1
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ ├─┬ apollo-graphql@0.9.3
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ ├─┬ apollo-server-plugin-base@3.2.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ apollo-server-types@3.2.0
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ ├─┬ graphql-extensions@0.15.0
│ │ ├─┬ apollo-server-types@0.9.0
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ ├─┬ graphql-scalars@1.10.1
│ │ └── graphql@15.5.3 deduped
│ ├─┬ graphql-tools@7.0.5
│ │ ├─┬ @graphql-tools/batch-delegate@7.0.2
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/batch-execute@7.1.2
│ │ │ ├─┬ @graphql-tools/utils@7.10.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/code-file-loader@6.3.1
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/delegate@7.1.5
│ │ │ ├─┬ @graphql-tools/schema@7.1.5
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ ├─┬ @graphql-tools/utils@7.10.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/git-loader@6.2.6
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/github-loader@6.2.5
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/graphql-file-loader@6.2.7
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/graphql-tag-pluck@6.5.1
│ │ │ ├─┬ @graphql-tools/utils@7.10.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/json-file-loader@6.2.6
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/links@7.1.0
│ │ │ ├─┬ @graphql-tools/utils@7.10.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ ├─┬ apollo-upload-client@14.1.3
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/load-files@6.4.0
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/load@6.2.8
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/mock@7.0.0
│ │ │ ├─┬ @graphql-tools/schema@7.1.5
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ ├─┬ @graphql-tools/utils@7.10.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/module-loader@6.2.7
│ │ │ ├─┬ @graphql-tools/utils@7.10.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/optimize@1.0.1
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/resolvers-composition@6.4.0
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/schema@7.1.5
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/stitch@7.5.3
│ │ │ ├─┬ @graphql-tools/schema@7.1.5
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ ├─┬ @graphql-tools/utils@7.10.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/url-loader@6.10.1
│ │ │ ├─┬ graphql-ws@4.9.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ ├── graphql@15.5.3 deduped
│ │ │ └─┬ subscriptions-transport-ws@0.9.19
│ │ │   └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/utils@7.10.0
│ │ │ └── graphql@15.5.3 deduped
│ │ ├─┬ @graphql-tools/wrap@7.0.8
│ │ │ ├─┬ @graphql-tools/schema@7.1.5
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ ├─┬ @graphql-tools/utils@7.10.0
│ │ │ │ └── graphql@15.5.3 deduped
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ └── graphql@15.5.3 deduped
├─┬ @censored/clients@0.0.335 -> ./packages/clients
│ ├─┬ @apollo/client@3.4.10 invalid: "~3.2.5 || ~3.3.0" from node_modules/graphql-tools
│ │ ├─┬ @graphql-typed-document-node/core@3.1.0
│ │ │ └── graphql@15.5.3 deduped
│ │ └── graphql@15.5.3 deduped
│ └── graphql@15.5.3 deduped
├─┬ @censored/codegen-backend-tests@0.0.211 -> ./packages/codegen-backend-tests
│ └── graphql@15.5.3 deduped
├─┬ @censored/mobile@1.14.4 -> ./packages/mobile
│ ├─┬ apollo-link-token-refresh@0.3.2
│ │ └── graphql@15.5.3 deduped
│ └── graphql@15.5.3 deduped
├─┬ @censored/promo@0.0.227 -> ./packages/promo
│ └── graphql@15.5.3 deduped
├─┬ @censored/schema@0.0.211 -> ./packages/schema
│ └── graphql@15.5.3 deduped
└─┬ @censored/web@0.1.447 -> ./packages/web
  └── graphql@15.5.3 deduped
npm ls @apollo/client
@censored/root@0.0.147 /Volumes/Projects/censored
├─┬ @censored/backend@0.0.482 -> ./packages/backend
│ └─┬ graphql-tools@7.0.5
│   ├── @apollo/client@3.4.10 deduped invalid: "~3.2.5 || ~3.3.0" from node_modules/graphql-tools
│   └─┬ @graphql-tools/links@7.1.0
│     ├── @apollo/client@3.4.10 deduped invalid: "~3.2.5 || ~3.3.0" from node_modules/graphql-tools, "~3.2.5 || ~3.3.0" from node_modules/@graphql-tools/links
│     └─┬ apollo-upload-client@14.1.3
│       └── @apollo/client@3.4.10 deduped invalid: "~3.2.5 || ~3.3.0" from node_modules/graphql-tools, "~3.2.5 || ~3.3.0" from node_modules/@graphql-tools/links
├─┬ @censored/clients@0.0.335 -> ./packages/clients
│ └── @apollo/client@3.4.10 invalid: "~3.2.5 || ~3.3.0" from node_modules/graphql-tools
├─┬ @censored/mobile@1.14.4 -> ./packages/mobile
│ ├── @apollo/client@3.4.10 deduped
│ ├─┬ apollo-link-token-refresh@0.3.2
│ │ └── @apollo/client@3.4.10 deduped invalid: "~3.2.5 || ~3.3.0" from node_modules/graphql-tools
│ └─┬ apollo3-cache-persist@0.12.1
│   └── @apollo/client@3.4.10 deduped invalid: "~3.2.5 || ~3.3.0" from node_modules/graphql-tools
├─┬ @censored/promo@0.0.227 -> ./packages/promo
│ └── @apollo/client@3.4.10 deduped
└─┬ @censored/web@0.1.447 -> ./packages/web
  └── @apollo/client@3.4.10 deduped

@wokayme
Copy link

wokayme commented Sep 25, 2021

@benjamn I have the same error. I am not as familiar with Apollo Code to know how to fix it but I think maybe my debugging will help a bit ;)
It looks like
node_modules/@apollo/client/utilities/globals/globals.cjs.js instead of resolvin dependency resolve the second file in the build folder node_modules/@apollo/client/utilities/globals/graphql.js if I delete this file problem disappear immediately 🤔

Screenshot 2021-09-25 at 21 26 08

final build requires some improvements.

@benjamn
Copy link
Member

benjamn commented Oct 1, 2021

@wokayme See #8862 for a similar fix (coming in the next 3.4.x release)!

@doomsower Does React Native have a setting like webpack's resolve.preferRelative that could explain this (React Native / Metro) module resolution behavior? If so, then it makes sense the problem did not show up in the Node.js shell, but only when bundling the application.

@benjamn
Copy link
Member

benjamn commented Oct 4, 2021

@doomsower @wokayme This should be fixed in @apollo/client@3.4.16 (and/or @apollo/client@3.5.0-rc.1). Please let us know if you still encounter problems after updating!

@benjamn benjamn closed this as completed Oct 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants