Closed
Description
🚀 Feature Proposal
If you have Node 13 and jest.config.js
file in a package with type=module
then Node will emit a warning:
(node:8906) Warning: require() of ES modules is not supported.
require() of /home/spyke/Projects/undercut/packages/undercut/jest.config.js from /home/spyke/Projects/undercut/node_modules/jest-config/build/readConfigFileAndSetRootDir.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.config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/spyke/Projects/undercut/packages/undercut/package.json.
In case of manually specifying the config fole with --config jest.config.cjs
it fails with an error:
The --config option requires a JSON string literal, or a file path with a .js or .json extension.
Example usage: jest --config ./jest.config.js
Using ES Modules syntax for config file gives an error too:
SyntaxError: Unexpected token 'export'
The issue is the same as babel/babel#10595. .cjs
is mandatory, but being able to load an ESM from .js
or .mjs
is nice to have too.
Motivation
Support ES Modules workflows in Node13+
Example
Configuring Jest in packages with type=module
and config file named jest.config.cjs