Jest-puppeteer: How can I use "jest-puppeteer.config.js" with "type": "module"?

Created on 23 Dec 2019  ·  2Comments  ·  Source: smooth-code/jest-puppeteer

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?

question ❓

Most helpful comment

While jest-puppeteer.config.cjs is not yet automatically detected/supported, you can set JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs in the meantime.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xiaoyuhen picture xiaoyuhen  ·  5Comments

testerez picture testerez  ·  6Comments

igneel64 picture igneel64  ·  5Comments

songguohfut picture songguohfut  ·  6Comments

Pyrolistical picture Pyrolistical  ·  6Comments