I am in this example application : examples/create-react-app
When I enable this in my package.json:
...
"type": "module",
...
I have this error:
yarn run v1.19.1
$ jest -c integration/jest.config.json
Determining test suites to run...(node:18974) Warning: require() of ES modules is not supported.
require() of /Users/stephane/Work/github.com/smooth-code/jest-puppeteer/examples/create-react-app/jest-puppeteer.config.js from /Users/stephane/Work/github.com/smooth-code/jest-puppeteer/examples/create-react-app/node_modules/jest-environment-puppeteer/lib/readConfig.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename jest-puppeteer.config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/stephane/Work/github.com/smooth-code/jest-puppeteer/examples/create-react-app/package.json.
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/stephane/Work/github.com/smooth-code/jest-puppeteer/examples/create-react-app/jest-puppeteer.config.js
at Module._extensions..js (internal/modules/cjs/loader.js:1163:13)
at Object.newLoader [as .js] (/Users/stephane/Work/github.com/smooth-code/jest-puppeteer/examples/create-react-app/node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:983:32)
at Function.Module._load (internal/modules/cjs/loader.js:891:14)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:72:18)
at readConfig (/Users/stephane/Work/github.com/smooth-code/jest-puppeteer/examples/create-react-app/node_modules/jest-environment-puppeteer/lib/readConfig.js:50:29)
at async setup (/Users/stephane/Work/github.com/smooth-code/jest-puppeteer/examples/create-react-app/node_modules/jest-environment-puppeteer/lib/global.js:19:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
How can I fix that?
Node 14 and Node 12 now have this unflagged, is there a plan to support this @gregberge ?
Could an alternative be support for jest-puppeteer.config.cjs ?
While jest-puppeteer.config.cjs is not yet automatically detected/supported, you can set JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs in the meantime.
Most helpful comment
While
jest-puppeteer.config.cjsis not yet automatically detected/supported, you can setJEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjsin the meantime.