Skip to content
Advertisement

ES6 import for ‘ava’ test not working

I followed the docs to create my first test using ava but it doesn’t seem to run properly. I get the error below. I tried adding import 'babel-register'; at the top of the file, and it works, but only if I run one specific test file. e.g. ava ./test/helpers/test_helper.js. Running ava on its own though… results in the import error below. Does anyone else know how to fix this? The getting started guide uses ES6 import and I have no idea why mine doesn’t just work.

(function (exports, require, module, __filename, __dirname) { import test from ‘ava’; ^^^^^^ SyntaxError: Unexpected token import

test.js

JavaScript

Advertisement

Answer

Add to your package.json

JavaScript

Your .babelrc

JavaScript

And then your imports should work.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement