Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

ava 4.0.1 does not work with non-native ESM, i.e., esm shim #2951

Closed
tcollinsworth opened this issue Jan 22, 2022 · 4 comments
Closed

ava 4.0.1 does not work with non-native ESM, i.e., esm shim #2951

tcollinsworth opened this issue Jan 22, 2022 · 4 comments

Comments

@tcollinsworth
Copy link

@tcollinsworth AVA 4 works just fine with CJS. Being a Node.js test runner, for ESM support we rely on Node.js' standard behavior.

Originally posted by @novemberborn in #2293 (comment)

@novemberborn Upgrading ava from 3.15.0 to 4.0.1 with esm-wallaby shim for optional-chaining support throws:

SyntaxError: Cannot use import statement outside a module
@novemberborn
Copy link
Member

I'm not familiar with that shim. AVA 3 has special handling for the esm shim and that has been removed. You'll have to register it as a CJS loader somehow.

@tcollinsworth
Copy link
Author

tcollinsworth commented Jan 22, 2022

AVA 3 has special handling for the esm shim and that has been removed.
You'll have to register it as a CJS loader somehow.

Any guidance on how to do that?

... WHATWG JSON modules specification are still being standardized, and are experimentally supported...
https://nodejs.org/api/esm.html#json-modules

The esm-wallaby lib is just a fork of the esm module but updated to support optional chaining (elvis operator). It works in ava 3.15.0, but fails with that error when updated to ava 4.0.1. I'm assuming this is due to removing support of esm?

ava.config.cjs

module.exports = {
  files: [
    '**/__tests__/**/*test*.js',
  ],
  ...
  require: [
    'ignore-styles',
    'esm-wallaby',
  ],
}

@novemberborn
Copy link
Member

Correct. We used to recognize a symbol from the esm package and use it for subsequent requires, but that has been removed. I imagine there's a way to make it work like say @babel/register but I haven't looked closely.

@novemberborn
Copy link
Member

You can specify node arguments to turn on experimental Node.js features. AVA does not do that by itself.

@avajs avajs locked and limited conversation to collaborators Jan 23, 2022
@novemberborn novemberborn converted this issue into discussion #2953 Jan 23, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants