Skip to content

Can't make custom Babel configuration specific for ava #1640

Closed
@willnode

Description

@willnode

Description

In package.json I have this configuration (minimum config to make ava able to transpile my sources):

{
	"ava": {
		"require": "babel-register",
		"babel": "inherit"
	},
	"babel": {
		"presets": [
			"@ava/stage-4"
		]
	},
}

Works very good. But according to example from this documentation, I can move the babel configuration to be specifiv for ava:

  "ava": {
    "require": "babel-register",
    "babel": {
      "presets": [
        "@ava/stage-4"
      ]
    }
  }

But then it does not work.

Test Source

Modified for demonstration.

test.js:

import test from 'ava';
import {default as foo} from './foo';
test(t => { t.true(foo.bar === "bar") });

foo.js:

export default { bar: "bar" }

Error Message & Stack Trace

The following is unmodified stack trace from my project:

import test from 'ava';
^^^^^^

SyntaxError: Unexpected token import
    at new Script (vm.js:51:7)
    at createScript (vm.js:138:10)
    at Object.runInThisContext (vm.js:199:10)
    at Module._compile (module.js:624:28)
    at extensions.(anonymous function) (X:\@Web\webpack-explorer\node_modules\require-precompiled\index.js:13:11)
    at Object.require.extensions.(anonymous function) [as .js] (X:\@Web\webpack-explorer\node_modules\ava\lib\process-adapter.js:100:4)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)

  1 exception

  × test.js exited with a non-zero exit code: 1

Config

Copy the relevant section from package.json:

  "ava": {
    "require": "babel-register",
    "babel": {
      "presets": [
        "@ava/stage-4"
      ]
    }
  }

No other babel config in babel.rc or in package.json (outside ava).

EXTRA: If I define babel config both inside and outside ava package.json, test will run OK. (is babel config inside ava config is ignored?)

Command-Line Arguments

Copy your npm build scripts or the ava command used:

ava

Relevant Links

My project is somewhat huge in depedencies, but here just in case. modify package.json to above before running.

Environment

node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"

ava --version
npm --version
Node.js v9.4.0
win32 10.0.16299

0.24.0
5.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions