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

HOW-TO: ES Modules with @std/esm #1590

Closed
motss opened this issue Nov 16, 2017 · 6 comments · Fixed by #1593
Closed

HOW-TO: ES Modules with @std/esm #1590

motss opened this issue Nov 16, 2017 · 6 comments · Fixed by #1593

Comments

@motss
Copy link
Contributor

motss commented Nov 16, 2017

If you're using @std/esm for your projects, ava will not be able to read your import test from 'ava'; if you're not transpiling ES modules.

The following configuration in package.json will help you out:

{
...
"@std/esm": {
  "esm": "all",
  "cjs": true,
  "gz": true,
  "await" true
},
"ava": {
  "require": [
    "@std/esm"
  ]
}
...
}

Hope this helps! 🎉

@sindresorhus
Copy link
Member

@motss Would you be able to submit a recipe?

See: https://github.com/avajs/ava/tree/master/docs/recipes

@motss motss changed the title HOW-TO: ES Modules with ts-node + @std/esm HOW-TO: ES Modules with @std/esm Nov 17, 2017
@motss
Copy link
Contributor Author

motss commented Nov 17, 2017

@sindresorhus PTAL at the PR #1593

@dacz
Copy link

dacz commented Dec 18, 2017

It doesn't work for me. I use flow so my .babelrc:

{
  "presets": ["@babel/preset-flow"]
}

and package.json

...
"@std/esm": { "esm": "all", "cjs": true },
  "ava": {
    "files": ["**/**/*.test.js"],
    "require": ["@std/esm", "@babel/register"],
    "babel": {
      "babelrc": true
    }
  },
...

I tried all possible combinations in require section of ava and in @std/esm settings.

Outside ava `@std/esm works like a charm. And w/o @std/esm ava works (with some limitations based on babel7).

@jdalton
Copy link
Contributor

jdalton commented Dec 18, 2017

@dacz head over to the @std/esm repo and file the issue there with a simple repro repo and I'll investigate.

@motss
Copy link
Contributor Author

motss commented Dec 18, 2017

@dacz Thanks for reporting the issue. Are you using Babel 6 or 7? Mind filing an issue at @std/esm as @jdalton suggested with your Babel config to assist in the investigation?

@jdalton
Copy link
Contributor

jdalton commented Dec 22, 2017

It looks like there was complications with ava support for test files.
See standard-things/esm#197 (comment).

Packages using @std/esm still work with ava.
It's just that ava handles ESM tightly on test files at the moment. Related to #709.

novemberborn referenced this issue Jan 30, 2018
* support @std/esm

* fix path test for windows

* fix linter error

* Stricter regex. Use shorthand .esmrc file in fixture.

* update package-lock.json
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

Successfully merging a pull request may close this issue.

4 participants