yarn init
yarn add ava
export default value => 1
import value from './obj.js'
export default value
import test from 'ava'
import obj from './main.js'
test('This will fail in AVA', t => {
t.is(1+1, 2)
})
1 uncaught exception
Uncaught exception in main.js
c:\ava\main.js:1
import value from './obj.js'
^^^^^^
SyntaxError: Unexpected token import
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test:watch: `ava -- --watch --verbose`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test:watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\failure\AppData\Roaming\npm-cache\_logs\2018-08-14T17_06_25_188Z-debug.log
{
"name": "test",
"version": "1.0.0",
"scripts": {
"test": "ava --verbose",
"test:watch": "ava -- --watch --verbose"
},
"dependencies": {
},
"devDependencies": {
"ava": "1.0.0-beta.7"
}
}
npm run test:watch
Windows 10, Node 8.11.3 LTS, Ava 1.0.0-beta.7, npm 5.6.0
Sorry you're having problems with this @onexdata. The issue is that AVA only compiles your test files. But since you're using ES module syntax, you need to compile source files too.
Going by what you've posted here I don't think you have a Babel compilation step? That would explain why the Babel recipe didn't help — you may not have configured Babel for @babel/register to work.
You may be interested in using the esm package as is described here: https://github.com/avajs/ava/blob/v1.0.0-beta.7/docs/recipes/es-modules.md
(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)
Well I'm trying to use AVA for node only, and Node 8.x supports ES6 / import out of the box, so there is no compilation step or need for Babel.
I'm a little puzzled what is going on since the test itself uses the import statement, yet the code the test is testing also uses it, but fails. Is there some kind of directive that tells AVA not to use ES6 that I can bypass?
This is only for server/Node/back end code and has nothing to do with the front-end and never will.
The link you gave has a link to disable AVA's use of Babel all together and here:
https://github.com/avajs/ava/blob/v1.0.0-beta.7/docs/recipes/babel.md#preserve-es-module-syntax
It suggests putting this in package.json:
"ava": {
"babel": false,
"compileEnhancements": false
},
But when I do that I get this:
```
× Unexpected Babel configuration for AVA. See https://github.com/avajs/ava#es2017-support for allowed values.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test:ava --verbose`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\nsteele\AppData\Roaming\npm-cache_logs\2018-08-14T21_58_24_743Z-debug.log
````
The URL the error suggests (https://github.com/avajs/ava#es2017-support) doesn't exist (the anchor doesn't exist so it just goes to the main page)
Oh my GOSH Node doesn't even support import yet 😧 ...
Thanks.
smacks forehead
Yes it's all a little bit confusing. I wonder if we should default to CJS instead, see #1908. Would love to know if that would've helped you in this case.
Most helpful comment
Sorry you're having problems with this @onexdata. The issue is that AVA only compiles your test files. But since you're using ES module syntax, you need to compile source files too.
Going by what you've posted here I don't think you have a Babel compilation step? That would explain why the Babel recipe didn't help — you may not have configured Babel for
@babel/registerto work.You may be interested in using the
esmpackage as is described here: https://github.com/avajs/ava/blob/v1.0.0-beta.7/docs/recipes/es-modules.md(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)