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

Custom babel configuration #685

Closed
rightaway opened this issue Mar 26, 2016 · 8 comments
Closed

Custom babel configuration #685

rightaway opened this issue Mar 26, 2016 · 8 comments

Comments

@rightaway
Copy link

Description

I have this in my package.json (tried the inherit way as well). But when I run ava (version 0.13.0) I get a SyntaxError: Unexpected token import.

  "ava": {
    "babel": {
      "presets": [
        "es2015",
        "stage-0"
      ]
    }
  },
  "babel": {
    "presets": [
      "es2015",
      "stage-0"
    ]
  },

In the test file itself, the import seems to work fine import server from '../index';, because the error is being reported from within the ../index.js file, so it's strange.

Environment

Node.js v5.5.0
linux 4.4.1-2-ARCH
@jamestalmage
Copy link
Contributor

@rightaway, add "require": ["babel-register"] to your AVA config:

  "ava": {
    "babel": {
      "presets": [
        "es2015",
        "stage-0"
      ]
    },
    "require": ["babel-register"]
  },
  "babel": {
    "presets": [
      "es2015",
      "stage-0"
    ]
  },

AVA currently only supports transpiling your test files for you. Not your source files. This is why you need to use babel-register. Note that we do intend to add the source transpilation feature at some point, so be sure to watch release notes when upgrading versions.

@rightaway
Copy link
Author

Now it looks like this and has resolved that problem. But I'm getting ReferenceError: regeneratorRuntime is not defined. Seems like I need babel-polyfill to solve this? But where should I define this in package.json or elsewhere?

  "ava": {
    "babel": "inherit",
    "require": ["babel-register"]
  },
  "babel": {
    "presets": [
      "es2015",
      "stage-0"
    ]
  },

@jamestalmage
Copy link
Contributor

Hmm. That's weird. Try npm install babel-runtime

@rightaway
Copy link
Author

Have just tried it but I get the same error. Any other ideas?

@jamestalmage
Copy link
Contributor

Can you create a project with a minimal reproduction and upload to github? It will be easier for us to troubleshoot that way.

@spudly
Copy link
Contributor

spudly commented Mar 28, 2016

Just require babel-polyfill also:

  "ava": {
    "babel": "inherit",
    "require": ["babel-register", "babel-polyfill"]
  },

@rightaway
Copy link
Author

@spudly works, thank you. Just out of curiosity, it seems like babel-register and babel-polyfill were already in my node_modules folder (probably as dependencies of other babel stuff). Is it good practice to explicitly declare both of these under devDependencies in package.json, or should I just leave it as is?

@spudly
Copy link
Contributor

spudly commented Mar 29, 2016

@rightaway, I would definitely add it as an explicit dev dependency.

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