Intended outcome:
Importing '@apollo/client' into an ES module works.
In my experimenting with a fix, I found antfu-collective/vite-ssg#241 and added the postinstall script to add an exports property to the package.json files in the client and client/core packages.
The client package:
"exports": {
".": {
"import": "./index.js",
"require": "./main.cjs",
"types": "./index.d.ts"
},
"./core": {
"import": "./index.js",
"require": "./core.cjs",
"types": "./index.d.ts"
},
"./react": {
"import": "./react/index.js",
"require": "./react/react.cjs",
"types": "./react/index.d.ts"
},
"./react/context": {
"import": "./react/context/index.js",
"require": "./react/context/context.cjs",
"types": "./react/context/index.d.ts"
},
"./*": "./*"
}
The client/core package:
"exports": {
".": {
"require": "./core.cjs",
"import": "./index.js",
"types": "./index.d.ts"
}
}
Actual outcome:
Error from Node.js:
SyntaxError: Named export 'ApolloClient' not found. The requested module '@apollo/client' is a CommonJS module, which may not support all module.exports as named exports.
How to reproduce the issue:
Install Node.js version 18.7.0. Set up a project with "type": "module". Install @apollo/client and import it this way:
import { ApolloClient } from '@apollo/client';
Run Node.
Versions
System:
OS: macOS 12.4
Binaries:
Node: 18.7.0 - ~/.nvm/versions/node/v18.7.0/bin/node
npm: 8.15.0 - ~/.nvm/versions/node/v18.7.0/bin/npm
Browsers:
Chrome: 103.0.5060.134
Safari: 15.5
npmPackages:
@apollo/client: ^3.6.9 => 3.6.9
Intended outcome:
Importing '@apollo/client' into an ES module works.
In my experimenting with a fix, I found antfu-collective/vite-ssg#241 and added the postinstall script to add an
exportsproperty to thepackage.jsonfiles in theclientandclient/corepackages.The
clientpackage:The
client/corepackage:Actual outcome:
Error from Node.js:
How to reproduce the issue:
Install Node.js version 18.7.0. Set up a project with
"type": "module". Install@apollo/clientand import it this way:Run Node.
Versions