-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support loading of ESM files #13
Comments
Possibly related. I'm using Babel to support JSX files. I get: Uncaught exception in tests/index.jsx
./tests/index.jsx:13
const _require = (0, _module.createRequire)(import.meta.url);
^^^^
SyntaxError: Cannot use 'import.meta' outside a module Then I disable the ES Modules compilation with: "presets": [
["module:@ava/babel/stage-4", false]
] and I get: Uncaught exception in tests/index.jsx
./tests/index.jsx:1
import { createRequire } from 'module';
^^^^^^
SyntaxError: Cannot use import statement outside a module I think this is due to:
In my case, I have |
Is AVA using @babel/register? Because I think this is not possible at the moment, according to the docs:
|
No, we install a hook to rewrite |
Yes but with our Babel support we still |
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: export function hello() {
return 'world';
} And my test: import test from 'ava'
import { hello } from '../src/hello.js''
test('see me', (t) => {
t.is(hello(), 'world')
}) package type is set to "module". node version 14.16.0. The result: passing tests. now, when I try to gather code coverage, running
{
"all": false,
"reporter": ["html", "text"],
"exclude": ["node_modules"],
"include": ["src/hello.js"],
"extension": [".js"]
} I tried using Istanbul's "esm-loader":
I appreciate your help with this issue! |
For what it's worth, I was able to get coverage with the existing .nycrc using c8.
|
Just use Is there a workaround at the moment? |
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:L369Assuming 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.The text was updated successfully, but these errors were encountered: