Skip to content

Commit

Permalink
Add "type": "module" to @apollo/client/core
Browse files Browse the repository at this point in the history
Consider trying to load `@apollo/client/core` in node.js

```bash
node -v # 16.3.0
```
```js
// server/index.js
import { ApolloClient } from '@apollo/client/core';
```
> import { ApolloClient, InMemoryCache } from '@apollo/client/core/index.js';
>          ^^^^^^^^^^^^
> SyntaxError: Named export 'ApolloClient' not found. The requested module '@apollo/client/core/index.js' is a CommonJS module, which may not support all module.exports as named exports.
> CommonJS modules can always be imported via the default export, for example using:

```js
import AC from '@apollo/client/core';
const { ApolloClient } = AC;
```
> (node:35704) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
> (Use `node --trace-warnings ...` to show where the warning was created)
> /path/to/node_modules/@apollo/client/core/index.js:1
> export { ApolloClient, mergeOptions, } from "./ApolloClient.js";
> ^^^^^^
> 
> SyntaxError: Unexpected token 'export'


adding `"type": "module"` to core will solve those errors nicely
  • Loading branch information
bennypowers committed Jun 18, 2021
1 parent df05ff3 commit 26c09e2
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions config/prepareDist.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ entryPoints.forEach(function buildPackageJson({
main: `${bundleName}.cjs.js`,
module: 'index.js',
types: 'index.d.ts',
...dirs.includes('core') && { type: "module" },
sideEffects: false,
}, null, 2) + "\n",
);
Expand Down

0 comments on commit 26c09e2

Please sign in to comment.