nyc icon indicating copy to clipboard operation
nyc copied to clipboard

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

Open robrich opened this issue 1 year ago • 0 comments

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:

  • Rename config to nyc.config.cjs: doesn't pick up config
  • Rename config to nyc.config.ts: doesn't pick up config
  • Change file content to ES6 module syntax: different error, but still errors

robrich avatar May 11 '23 02:05 robrich