apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.38k stars 2.66k forks source link

Apollo Client 3.4.0 and higher breaks use of pkg #9487

Open traviscollins opened 2 years ago

traviscollins commented 2 years ago

Intended outcome: Use the pkg to build native executables. My project depended on @apollo/client@3.2.5 for many months, with no issues.

Actual outcome: I upgraded to 3.5.10 and now the pkg output executable throws an related to apollo/client's use of ts-invariant/process.

./dist/apollo-client-error-tsinvariant-process-pkg-macos
pkg/prelude/bootstrap.js:1740
      throw error;
      ^

Error: Cannot find module 'ts-invariant/process'
Require stack:
- /snapshot/react-apollo-error-template/node_modules/@apollo/client/utilities/utilities.cjs.js
- /snapshot/react-apollo-error-template/node_modules/@apollo/client/core/core.cjs.js
- /snapshot/react-apollo-error-template/node_modules/@apollo/client/main.cjs.js
- /snapshot/react-apollo-error-template/src/index.js
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1819:46)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Module.require (pkg/prelude/bootstrap.js:1719:31)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/snapshot/react-apollo-error-template/node_modules/@apollo/client/utilities/utilities.cjs.js)
    at Module._compile (pkg/prelude/bootstrap.js:1794:22)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/snapshot/react-apollo-error-template/node_modules/@apollo/client/utilities/utilities.cjs.js',
    '/snapshot/react-apollo-error-template/node_modules/@apollo/client/core/core.cjs.js',
    '/snapshot/react-apollo-error-template/node_modules/@apollo/client/main.cjs.js',
    '/snapshot/react-apollo-error-template/src/index.js'
  ],
  pkg: true
}

How to reproduce the issue:

https://github.com/traviscollins/react-apollo-error-template

Versions

Affects 3.4.0 and higher.

xelaz commented 2 years ago

Same problem with apollo client > 3.4.x but with 3.3.21 it works

pkg/prelude/bootstrap.js:1833
      throw error;
      ^

Error: Cannot find module 'ts-invariant/process'
Require stack:
- /snapshot/project/tool/node_modules/@apollo/client/utilities/globals/globals.cjs.js
- /snapshot/project/tool/node_modules/@apollo/client/core/core.cjs.js
- /snapshot/project/tool/node_modules/apollo-upload-client/public/createUploadLink.js
- /snapshot/project/tool/node_modules/apollo-upload-client/public/index.js
- /snapshot/project/tool/build/apollo.js
- /snapshot/project/tool/build/export-order.js
- /snapshot/project/tool/build/boot.js
- /snapshot/project/tool/build/index.js
jpvajda commented 2 years ago

Hello! Please try upgrading to the most current version 3.6.8, You can review our changelog for details on what was released recently. If you still have any issue just let us know. Thank you!

veeramarni commented 1 year ago

I still have issues with server-side rendering. I'm using the latest version 3.7.1

/Users/fullstack-pro/servers/frontend-server/dist/main.js:1
Error: Cannot find module './core/index.js'
Require stack:
- /Users/fullstack-pro/servers/frontend-server/dist/main.js
- /Users/fullstack-pro/servers/frontend-server/dist/index.js
    at Object.6082 (/Users/fullstack-pro/servers/frontend-server/dist/webpack:/sample-stack-frontend-server/src/index.ts:1)
    at __webpack_require__ (/Users/fullstack-pro/servers/frontend-server/dist/webpack:/sample-stack-frontend-server/webpack/bootstrap:19:1)
    at Object.1005 (/Users/fullstack-pro/servers/frontend-server/dist/webpack:/sample-stack-frontend-server/src/backend/website.tsx:3:1)
    at __webpack_require__ (/Users/fullstack-pro/servers/frontend-server/dist/webpack:/sample-stack-frontend-server/webpack/bootstrap:19:1)
error Command failed with exit code 1.
veeramarni commented 1 year ago

The issue is in my end. Not issue for me now.

jwielebnowski commented 1 year ago

Any update on this? I confirm that all is fine on 3.3.21. 3.6.8 is broken.

MihaiLupoiu commented 1 year ago

I confirm that using pkg@5.8.0 all is fine using @apollo/client@3.3.21 and breaks using @apollo/client@3.7.3.

Cheking the file difference between 3.3.21 and 3.4.0 I don't see any mentioning of the ts-invariant/process except in one place. src/utilities/globals/graphql.ts

Diff v3.3.21 - v3.4.0

I also see that there is a normalization process happening for ts-invariant/process, not sure if it would affect pkg: https://github.com/apollographql/apollo-client/blob/792ac32f5b5d23b3346fa07a4d8ac35f0e7e8d70/config/postprocessDist.ts#L100-L122