apollo-client icon indicating copy to clipboard operation
apollo-client copied to clipboard

yarn build/start import @apollo/client/core/core.cjs.js?

Open productdevbook opened this issue 3 years ago • 9 comments

Environment


  • Operating System: Darwin
  • Node Version: v16.13.0
  • Nuxt Version: 3.0.0-27276275.abfbd2f
  • Package Manager: [email protected]
  • Bundler: Vite
  • User Config: build
  • Runtime Modules: -
  • Build Modules: -

Describe the bug

yarn build yarn start

nuxt docs check -> https://v3.nuxtjs.org/concepts/esm

Reproduction

https://github.com/productdevbook/productdevbook.com

Additional context

No response

Logs

➜  productdevbook.com git:(main) yarn start
yarn run v1.22.15
$ node .output/server/index.mjs
Listening on http://localhost:3000
Directory import '/Users/productdevbook/Documents/GitHub/productdevbook.com/.output/server/node_modules/@apollo/client/core' is not supported resolving ES modules imported from /Users/productdevbook/Documents/GitHub/productdevbook.com/.output/server/chunks/app/server.mjs
Did you mean to import @apollo/client/core/core.cjs.js?
  at new NodeError (node:internal/errors:371:5)  
  at finalizeResolution (node:internal/modules/esm/resolve:412:17)  
  at moduleResolve (node:internal/modules/esm/resolve:932:10)  
  at defaultResolve (node:internal/modules/esm/resolve:1044:11)  
  at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)  
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)  
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)  
  at link (node:internal/modules/esm/module_job:75:36)

https://github.com/nuxt/framework/issues/1846

productdevbook avatar Nov 12 '21 10:11 productdevbook

v3.5.x some problem

productdevbook avatar Nov 19 '21 16:11 productdevbook

Please remove .js extension if you are using core.cjs.js Example import ApolloClientCore from '@apollo/client/core/core.cjs.js'; => import ApolloClientCore from '@apollo/client/core/core.cjs';

https://github.com/apollographql/apollo-client/releases/tag/v3.5.4 Since Apollo Client v3.5.0, CommonJS bundles provided by @apollo/client use a .cjs file extension rather than .cjs.js, so Node.js won't interpret them as ECMAScript modules. While this change should be an implementation detail, it may cause problems for the Metro bundler used by React Native, whose resolver.sourceExts configuration does not include the cjs extension by default.

vrana055 avatar Nov 25 '21 09:11 vrana055

Please remove .js extension if you are using core.cjs.js Example import ApolloClientCore from '@apollo/client/core/core.cjs.js'; => import ApolloClientCore from '@apollo/client/core/core.cjs';

https://github.com/apollographql/apollo-client/releases/tag/v3.5.4 Since Apollo Client v3.5.0, CommonJS bundles provided by @apollo/client use a .cjs file extension rather than .cjs.js, so Node.js won't interpret them as ECMAScript modules. While this change should be an implementation detail, it may cause problems for the Metro bundler used by React Native, whose resolver.sourceExts configuration does not include the cjs extension by default.

dont se .js -> https://github.com/productdevbook/productdevbook.com/blob/main/plugins/vue-apollo.ts check code please

productdevbook avatar Nov 25 '21 10:11 productdevbook

@productdevbook maybe it will work for you.

// eslint-disable-next-line import/extensions
import ApolloClientCore from '@apollo/client/core/core.cjs';

const {
  ApolloClient,
  InMemoryCache,
  createHttpLink,
} = ApolloClientCore;

vrana055 avatar Nov 25 '21 11:11 vrana055

@vrana055 This workaround works, but it would be nice if there would be a solution that doesn't need this. For example, other libraries (in my case vue apollo composable) import directly from @apollo/client/core which leads to problems.

tobiasdiez avatar Nov 25 '21 12:11 tobiasdiez

@vrana055 CleanShot 2021-11-28 at 10 33 04@2x

productdevbook avatar Nov 28 '21 07:11 productdevbook

Those workaround patches seems to work https://github.com/JabRef/JabRefOnline/tree/afc92ac85f317fb81d32f07be00944209eebfdae/patches can it be fixed on dependency site?

xxSkyy avatar Dec 12 '21 20:12 xxSkyy

3.5.6 same problem, is there any progress on this issue?

pipinet avatar Dec 25 '21 02:12 pipinet

same problem with v3.5.6, but, this https://stackoverflow.com/questions/70338215/error-while-trying-to-resolve-module-apollo-client-react-native/70352228 helped me.

mayconline avatar Jan 07 '22 18:01 mayconline