istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.55k stars 353 forks source link

nyc.config.js in `"type": "module"` project #1518

Open robrich opened 1 year ago

robrich commented 1 year ago

Repro steps:

  1. set package.json: "type": "module"
  2. create dynamic config: nyc.config.js file with any options
  3. run any nyc command: npx nyc npm run test

Expected behavior:

It loads the nyc.config settings then runs the test

Actual behavior:

ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'C:\path\to\my\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///C:/path/to/my/nyc.config.js:8:1
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)

or

Error: Failed to load nyc.config.js: require() of ES Module C:\path\to\my\nyc.config.js from C:\path\to\my\node_modules\@cypress\code-coverage\task-utils.js not supported.

Attempted work-arounds: