Open
Description
It's unclear to me how we would load compiled ESM files.
Our current approach is to install a hook on require.extensions
but this is ignored for ESM files: https://github.com/avajs/babel/blob/c9de6fc63f9bc61abcdfbc99ebf734c1ad5a9210/index.js#L366:L369
Assuming that paths in the Babel output are relative, we could simply import()
any given file and assume that everything else will follow. However this means code runs from a different directory leading to subtle failures.
Once we resolve this, we could add a default mjs
extension, though this would be a breaking change.
Activity
esm
: AVA 2 supportstype: module
, AVA 3 doesn't avajs/ava#2432fregante commentedon Sep 8, 2020
Possibly related. I'm using Babel to support JSX files. I get:
Then I disable the ES Modules compilation with:
and I get:
I think this is due to:
In my case, I have
type:module
in my package.json, so it should also be copied to the temporary directory.fregante commentedon Sep 8, 2020
Is AVA using @babel/register? Because I think this is not possible at the moment, according to the docs:
novemberborn commentedon Sep 8, 2020
No, we install a hook to rewrite
require()
calls.novemberborn commentedon Sep 8, 2020
Yes but with our Babel support we still
require()
rather thanimport()
. That's what this issue is about.richardeschloss commentedon Mar 21, 2021
Hi I'm interested in the progress of this issue but thought I'd chime in. I'm actually able to get tests to successfully run on ava when the package type is "module". However, I'm struggling to gain coverage with nyc.
As a very simple example, suppose I have src file:
./src/hello.js
:And my test:
./test/hello.js
:package type is set to "module". node version 14.16.0.
The result: passing tests.
now, when I try to gather code coverage, running
nyc ava
on it's own fails to cover the files..nycrc
:I tried using Istanbul's "esm-loader":
I appreciate your help with this issue!
richardeschloss commentedon Mar 21, 2021
For what it's worth, I was able to get coverage with the existing .nycrc using c8.
vjpr commentedon Sep 25, 2021
Just use
--experimental-loader
. Good docs here: https://nodejs.org/api/esm.html#esm_loadersIs there a workaround at the moment?