Skip to content
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

Use node experimental-modules? #1641

Closed
ghost opened this issue Jan 19, 2018 · 4 comments
Closed

Use node experimental-modules? #1641

ghost opened this issue Jan 19, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Jan 19, 2018

One way to avoid having to use babel, is to enable the --experimental-modules node feature.
So, for example, I'd run: node --experimental-modules main.mjs (mode here)

But, i can't seem to figure out how to make ava use experimental modules instead of relying on babel-register. Any clue?

@novemberborn
Copy link
Member

AVA does not recognize test files with .mjs extensions. See #631 (comment). That comment still assumes use of a transpiler or @std/esm. I'm not sure how much we should change AVA to work with experimental Node.js features, though I'm open to this as long as the changes are not too intrusive.

I imagine you can forward the --experimental-modules flag to the worker processes by running node --experimental-modules ./node_modules/.bin/ava. Perhaps you can then import .mjs source files from your tests.

@jrgleason
Copy link

@novemberborn Nope...

node --experimental-modules ./node_modules/.bin/ava ./src/test/js/webdriver/tests/sampleTest.mjs 
(node:1742) ExperimentalWarning: The ESM module loader is experimental.

  ✖ Couldn't find any files to test

node --experimental-modules ./node_modules/.bin/ava ./src/test/js/webdriver/tests/sampleTest.js 
(node:1744) ExperimentalWarning: The ESM module loader is experimental.

⠹ (node:1745) ExperimentalWarning: The ESM module loader is experimental.

  1 test passed

@novemberborn
Copy link
Member

@jrgleason you need to be using the latest AVA release (ava@next on npm), and configure it to recognize the mjs extension. But even then it may not work. #1810 has more discussion.

@dandv
Copy link

dandv commented May 7, 2019

Indeed, it didn't work. I tried node --experimental-modules node_modules/.bin/ava ava-test.mjs and got

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants