apollo-client
apollo-client copied to clipboard
yarn build/start import @apollo/client/core/core.cjs.js?
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
v3.5.x some problem
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.
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 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 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.
@vrana055
Those workaround patches seems to work https://github.com/JabRef/JabRefOnline/tree/afc92ac85f317fb81d32f07be00944209eebfdae/patches can it be fixed on dependency site?
3.5.6 same problem, is there any progress on this issue?
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.