question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nyc on ESM Node.js 13 (no babel)

See original GitHub issue

Does nyc work with ESM and Node.js 13 without babel?

I followed the steps from https://github.com/avajs/ava/blob/master/docs/recipes/code-coverage.md

My config from package.json is

"scripts": {
    "test": "ava",
    "coverage": "nyc ava"
},
"ava": {
    "files": [
      "src/test/**/*.spec.js"
    ],
    "require": [
      "./src/test/_setup-browser-env.js"
    ],
    "verbose": true
  }

When I run the coverage script I get this:

image

I don’t use babel, and imports are done with import not require. I’m on the latest versions of node.js, ava, nyc

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:18
  • Comments:28 (10 by maintainers)

github_iconTop GitHub Comments

11reactions
coreyfarrellcommented, Mar 10, 2020

nyc does not yet support coverage of node.js native ESM. It will take some time as node.js has just created API’s to make this possible though they are still experimental and subject to breakage. I’m working on creating an @istanbuljs/esm-loader-hook module that could be used as NODE_OPTIONS='--experimental-loader @istanbuljs/esm-loader-hook' nyc mocha, I’ll post here when I have updates for that. nyc won’t handle this transparently until the loader hook API’s are less experimental.

FWIW it looks like the currently available ESM transform hook is available in node.js ^12.16.0 || >=13.7.0. The minimum version could increase if additional breaking changes occur.

7reactions
brettz9commented, Apr 30, 2021

c8 is working for me with "type": "module".

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my NYC Code coverage not working with ESM?
I have the following code... App.mjs import express from "express"; const ...
Read more >
@istanbuljs/esm-loader-hook | Yarn - Package Manager
This loader hook makes it relatively easy to use NYC to check coverage of ESM running in node.js 13.7.0. Note this makes use...
Read more >
mochajs/mocha - Gitter
Ah. You're running Mocha through nyc, and using ESM? I'm assuming you're not using the esm package, but rather using Node's native support...
Read more >
Modules: Packages | Node.js v19.3.0 Documentation
When used to load a JavaScript text file that is not an ECMAScript module, ... are familiar with when using transpilation via tools...
Read more >
error require esm - You.com | The AI Search Engine You Control
js. Browsers do not implement this module system. Also, before I got it to work in node, I had to do npm install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found