Nyc on ESM Node.js 13 (no babel)
See original GitHub issueDoes 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:
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:
- Created 4 years ago
- Reactions:18
- Comments:28 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 asNODE_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.c8
is working for me with"type": "module"
.