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

@apollo-client 3.3.2 fails to compile due to wrong ts-invariant version resolved #7406

Closed
eugeneoshepkov opened this issue Dec 2, 2020 · 6 comments

Comments

@eugeneoshepkov
Copy link

eugeneoshepkov commented Dec 2, 2020

Intended outcome:
App compiles

Actual outcome:
App compilation is broken

App with the dependency of @apollo/client@^3.3.2 fails to compile, here's the error output:

WARNING in ./node_modules/@apollo/client/core/index.js 13:0-43
"export 'setVerbosity' (reexported as 'setLogVerbosity') was not found in 'ts-invariant'
 @ ./node_modules/@apollo/client/index.js
 @ ./src/components/App/App.tsx
 @ ./src/components/App/index.ts
 @ ./src/main.tsx
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./src/main.tsx

WARNING in ./node_modules/@apollo/client/core/index.js 14:0-12
"export 'setVerbosity' was not found in 'ts-invariant'
 @ ./node_modules/@apollo/client/index.js
 @ ./src/components/App/App.tsx
 @ ./src/components/App/index.ts
 @ ./src/main.tsx
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./src/main.tsx

TypeError: Object(...) is not a function
Module../node_modules/@apollo/client/core/index.js
./node_modules/@apollo/client/core/index.js:14
  11 | export { Observable, isReference, makeReference, } from "../utilities/index.js";
  12 | import { setVerbosity } from "ts-invariant";
  13 | export { setVerbosity as setLogVerbosity };
> 14 | setVerbosity("warn");
  15 | import gql from 'graphql-tag';
  16 | export var resetCaches = gql.resetCaches, disableFragmentWarnings = gql.disableFragmentWarnings, enableExperimentalFragmentVariables = gql.enableExperimentalFragmentVariables, disableExperimentalFragmentVariables = gql.disableExperimentalFragmentVariables;
  17 | export { gql };
View compiled

I believe it's because the older ts-variant version is resolved. apollo-link has a dependency on [email protected], while @apollo/client relies on [email protected]. My yarn.lock contains these two packages.

Apparently, this is not true in my case.

Meanwhile, I've fixed it via package.json's resolutions:

...
"resolutions": {
    "ts-invariant": "^0.5.0"
  },
...

Versions:
System:
OS: macOS 10.15.7
Binaries:
Node: 12.18.2 - ~/.nvm/versions/node/v12.18.2/bin/node
Yarn: 1.22.5 - /usr/local/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v12.18.2/bin/npm
Browsers:
Chrome: 87.0.4280.67
Safari: 14.0.1
npmPackages:
@apollo/client: ^3.3.2 => 3.3.2
@apollo/react-ssr: ^4.0.0 => 4.0.0
apollo-datasource-rest: ^0.9.5 => 0.9.5
apollo-server-hapi: ^2.19.0 => 2.19.0

@benjamn
Copy link
Member

benjamn commented Dec 2, 2020

@eugeneoshepkov The @apollo/[email protected] package requires [email protected] in package.json, so I don't understand why an older version of ts-invariant would be resolved. Are you installing ts-invariant directly in your application?

@benjamn benjamn added the 🏓 awaiting-contributor-response requires input from a contributor label Dec 2, 2020
@eugeneoshepkov
Copy link
Author

eugeneoshepkov commented Dec 3, 2020

@benjamn So it comes from graphql-tools, which in turn is a dependency of @graphql-codegen:
https://github.com/dotansimha/graphql-code-generator/blob/master/package.json

I don't have direct dependency of ts-invariant in the package.json

benjamn added a commit that referenced this issue Dec 4, 2020
apollographql/invariant-packages#53

This may also help with issues like #7406, where a _patch_ version update
(from 0.5.0 to 0.5.1) is not enough to force a dependency like
ts-invariant with multiple conflicting version constraints (from
@apollo/client and graphql-tools) to be updated, since version 0.5.0 is
still semantically compatible with the desired minimum version 0.5.1, so
ts-invariant remains outdated after updating @apollo/client, despite the
new version being clearly mandated in @apollo/client/package.json.

After updating the _minor_ version of ts-invariant in package.json (to
^0.6.0), there should be no risk of @apollo/client incorrectly resolving
the older [email protected] version.
benjamn added a commit that referenced this issue Dec 4, 2020
apollographql/invariant-packages#53

This update may also help with issues like #7406, where a patch
version update (from 0.5.0 to 0.5.1) is apparently not enough to force
a dependency like ts-invariant with multiple conflicting version
constraints (from @apollo/client and graphql-tools) to be updated,
since version 0.5.0 is still semantically compatible with the desired
minimum version 0.5.1, so ts-invariant remains outdated after updating
@apollo/client, despite the new version being clearly mandated in
@apollo/client/package.json.

After updating the minor version of ts-invariant in package.json (to
^0.6.0), there should be no risk of @apollo/client incorrectly resolving
the older [email protected] version, though there may end up being
multiple copies of ts-invariant in node_modules with different versions,
which is fine for this particular package.
@benjamn
Copy link
Member

benjamn commented Dec 7, 2020

@eugeneoshepkov If you update to @apollo/[email protected], this problem should disappear, thanks to #7414. Let us know what happens either way, so we can avoid problems like this in the future (that is, by using minor updates instead of patch updates in more cases).

@eugeneoshepkov
Copy link
Author

eugeneoshepkov commented Dec 9, 2020

@benjamn Thanks for the fast response! Unfortunately, I'm still having this issue. I wonder if it can be related to my webpack / babel configuration, if it changes default node_modules resolve logic. I have [email protected] in root node_modules folder and [email protected] in node_modules/@apollo/client/node_modules folder. And the error is still the same:

WARNING in ./node_modules/@apollo/client/core/index.js 13:0-43
"export 'setVerbosity' (reexported as 'setLogVerbosity') was not found in 'ts-invariant'
 @ ./node_modules/@apollo/client/index.js
 @ ./src/components/App/App.tsx
 @ ./src/components/App/index.ts
 @ ./src/main.tsx
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./src/main.tsx

WARNING in ./node_modules/@apollo/client/core/index.js 14:0-12
"export 'setVerbosity' was not found in 'ts-invariant'
 @ ./node_modules/@apollo/client/index.js
 @ ./src/components/App/App.tsx
 @ ./src/components/App/index.ts
 @ ./src/main.tsx
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./src/main.tsx

I've figured out that [email protected] eventually comes from @graphql-modules/[email protected]: https://github.com/Urigo/graphql-modules/blob/legacy/packages/core/package.json#L20

Update:

It turned out that it was because of resolve.modules configuration, which "forces all modules to resolve from the root node_modules": webpack/webpack#6505 (comment)

@benjamn Thanks again for your help!

@don-hover
Copy link

Bumping because I'm seeing this same problem when upgrading from 3.3.21 to 3.4.8.

I see this in the yarn lockfile:

ts-invariant@^0.4.0, ts-invariant@^0.6.1, ts-invariant@^0.9.0:
  version "0.6.2"
  resolved "https://registry.yarnpkg.com/ts-invariant/-/ts-invariant-0.6.2.tgz#2b95c0f25dd9da0c1d3b921e23ee5593133694d4"
  integrity sha512-hsVurayufl1gXg8CHtgZkB7X0KtA3TrI3xcJ9xkRr8FeJHnM/TIEQkgBq9XkpduyBWWUdlRIR9xWf4Lxq3LJTg==

So, although ts-invariant@^0.9.0 is being required by @apollo-client, version 0.6.2 of ts-invariant is being resolved. That's causing our build to fail with this error:

ERROR in ./node_modules/@apollo/client/utilities/globals/graphql.js 1:0-46                                              
Module not found: Error: Can't resolve 'ts-invariant/process' in '/usr/src/app/node_modules/@apollo/client/utilities/glo
bals'                                                                                                                   
resolve 'ts-invariant/process' in '/usr/src/app/node_modules/@apollo/client/utilities/globals'                          
  Parsed request is a module                                                                                            
  using description file: /usr/src/app/node_modules/@apollo/client/utilities/package.json (relative path: ./globals)    

@Myilvaganan
Copy link

Myilvaganan commented Oct 13, 2022

Worked!!! Thanks. I was facing issue with latest version of @apollo/client

WARNING in ./node_modules/@apollo/client/core/index.js 13:0-43
"export 'setVerbosity' (reexported as 'setLogVerbosity') was not found in 'ts-invariant'
 @ ./node_modules/@apollo/client/index.js
 @ ./src/components/App/App.tsx
 @ ./src/components/App/index.ts
 @ ./src/main.tsx
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./src/main.tsx

WARNING in ./node_modules/@apollo/client/core/index.js 14:0-12
"export 'setVerbosity' was not found in 'ts-invariant'
 @ ./node_modules/@apollo/client/index.js
 @ ./src/components/App/App.tsx
 @ ./src/components/App/index.ts
 @ ./src/main.tsx
 @ multi ./node_modules/react-dev-utils/webpackHotDevClient.js ./src/main.tsx

after resolving node_modules in webpack.config.js, it's working!!!

 resolve: {
       extensions: [".js", ".jsx", ".json", ".ts"],
       modules: [
           'node_modules'
       ]
   },
   resolveLoader: {
       modules: [
           'node_modules'
       ]
   },
   ``` 

@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.
Projects
None yet
Development

No branches or pull requests

4 participants