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
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
Tests run without errors.
npx envinfo --preset jestPaste 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
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.
Most helpful comment
Importing the
.cjsmodule 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.