这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@dnjstrom
Copy link

The ESM module is still exposed through the dedicated module property though for consumers that support it.

The ESM module is still exposed through the dedicated `module` property though for consumers that support it.
@dnjstrom
Copy link
Author

This change was prompted due to our jest tests breaking with the following error:

/../frontend/node_modules/d3-array/src/index.js:1

SyntaxError: Unexpected token 'export'

    > 1 | import { bisector } from "d3-array";
        | ^
      2 | 

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1726:14)
      at Object.<anonymous> (src/utils.ts:1:1)

Our code seem to import the ESM module but Jest doesn't transform esm modules in node_modules, simply expecting commonjs modules from libraries - causing the error. Changing the main property to the commonjs export fixes the error but still provide ESM modules for the tools that support them.

@mbostock
Copy link
Member

Thank you for the suggestion. Per the release notes, D3 now only provides ES modules for Node. CommonJS is no longer supported.

@mbostock mbostock closed this Sep 24, 2021
@dnjstrom
Copy link
Author

Ah, hadn't noticed that - sorry for the noise and thanks for the fast response! 👍

@dnjstrom dnjstrom deleted the patch-1 branch September 24, 2021 13:00
@dnjstrom
Copy link
Author

For anyone else stumbling across this question, the solution for us was to set the transformIgnorePatterns in jest.config.js like so:

  transformIgnorePatterns: ["/node_modules/(?!(d3-array|internmap))"],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants