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

Fresh AVA 7.0.0-rc.1 install displays "SyntaxError: Unexpected token import" on any ES6 import source #1905

Closed
onexdata opened this issue Aug 14, 2018 · 6 comments

Comments

@onexdata
Copy link

onexdata commented Aug 14, 2018

Description

yarn init
yarn add ava

source files:

obj.js:

export default value => 1

main.js:

import value from './obj.js'
export default value

Test Source

import test from 'ava'
import obj from './main.js'
test('This will fail in AVA', t => {
    t.is(1+1, 2)
})

Error Message & Stack Trace

  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

Config

{
  "name": "test",
  "version": "1.0.0",
  "scripts": {
    "test": "ava --verbose",
    "test:watch": "ava -- --watch --verbose"
  },
  "dependencies": {
  },
  "devDependencies": {
    "ava": "1.0.0-beta.7"
  }
}

Command-Line Arguments

npm run test:watch

Environment

Windows 10, Node 8.11.3 LTS, Ava 1.0.0-beta.7, npm 5.6.0

@onexdata
Copy link
Author

I've tried everything in this to no avail. I've googled for 2 hours now to no avail.

Tried...

this
this
this
this

...and many others. Nothing seems to do the trick. Would really like to try out Ava... seems incredibly complex to just use ES6 basic syntax...

@novemberborn
Copy link
Member

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.)

@onexdata
Copy link
Author

onexdata commented Aug 14, 2018

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.

@onexdata
Copy link
Author

onexdata commented Aug 14, 2018

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)

@onexdata
Copy link
Author

Oh my GOSH Node doesn't even support import yet 😧 ...

Thanks.

smacks forehead

@novemberborn
Copy link
Member

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.

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

2 participants