Jest: Importing a node module from react-spring/renderprops transforms it into an ES module and fails to run in node

Created on 21 Mar 2019  路  2Comments  路  Source: facebook/jest

馃悰 Bug Report

When importing a node module from react-spring/renderprops, it appears to be transformed to an ES module and fails to run.

    react-spring-bundle-example/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export default function _objectWithoutPropertiesLoose(source, excluded) {
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:451:17)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:493:19)
      at Object.<anonymous> (node_modules/react-spring/renderprops.js:7:53)

The imported module is not an ES module, so the source of the issue is unclear: https://unpkg.com/[email protected]/renderprops.js

Related issue: https://github.com/react-spring/react-spring/issues/601

To Reproduce

Minimal example repo: https://github.com/slikts/react-spring-bundle-example/

git clone [email protected]:slikts/react-spring-bundle-example.git .
npm i
npx jest

Expected behavior

Tests run without errors.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 11.9.0 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.5.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^24.5.0 => 24.5.0
Bug Report Needs Repro Needs Triage

Most helpful comment

Importing the .cjs module is just a workaround, and both modules are actually CJS (or more accurately, node modules; https://github.com/react-spring/react-spring/issues/601) and don't have ES6 module syntax; the ES6 module syntax is added by Jest somehow, which causes the error.

All 2 comments

Did you try add? /renderprops.cjs link

Importing the .cjs module is just a workaround, and both modules are actually CJS (or more accurately, node modules; https://github.com/react-spring/react-spring/issues/601) and don't have ES6 module syntax; the ES6 module syntax is added by Jest somehow, which causes the error.

Was this page helpful?
0 / 5 - 0 ratings