Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "type": "module" to @apollo/client/core and friends #8396

Merged
merged 4 commits into from
Jul 28, 2021

Commits on Jul 28, 2021

  1. Add "type": "module" to @apollo/client/core

    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
    bennypowers authored and benjamn committed Jul 28, 2021
    Configuration menu
    Copy the full SHA
    ee59d82 View commit details
    Browse the repository at this point in the history
  2. use "type": "module" for all packages

    bennypowers authored and benjamn committed Jul 28, 2021
    Configuration menu
    Copy the full SHA
    a597eff View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f5a7a58 View commit details
    Browse the repository at this point in the history
  4. Make resolveModuleIds.ts resolve bare/non-relative package imports, too.

    For example, this rewrites the import from "ts-invariant/process" in
    @apollo/client/utilities/globals/graphql.js to instead import from
    "ts-invariant/process/index.js, so Node.js won't complain about the
    directory import (even though ts-invariant/process/package.json exists).
    benjamn committed Jul 28, 2021
    Configuration menu
    Copy the full SHA
    60e18e9 View commit details
    Browse the repository at this point in the history