Skip to content

Tests files are not transpiled when the package is of type module #35

Open
@geoffreytools

Description

@geoffreytools

I get a syntax error when I try to use the pipeline operator |> in a test file

How to reproduce

Create a new project with just 3 files in it:

test.js

import test from 'ava';

test('the code is transpiled', t => {
    0 |> (x => x);
    t.pass();
})

.babelrc

{
    "plugins": [
        [
            "@babel/plugin-proposal-pipeline-operator",
            {"proposal": "minimal"}
        ]
    ]
}

package.json

{
    "type": "module",
    "ava": {
        "babel": true
    },
    "devDependencies": {
        "@ava/babel": "^2.0.0",
        "@babel/plugin-proposal-pipeline-operator": "^7.15.0",
        "ava": "^3.15.0"
    }
}

run npx ava:

$ npx ava

  × No tests found in test.js

  ─

  Uncaught exception in test.js

  SyntaxError: Unexpected token '>'

  ─

  1 uncaught exception

debugging

The problem can be "fixed" like so:

  • remove "type": "module" from package.json
  • replace the import by a require in the test file

ideas

It reminds me of this, from the @rollup/plugin-babel doc

When using @rollup/plugin-babel with @rollup/plugin-commonjs in the same Rollup configuration, it's important to note that @rollup/plugin-commonjs must be placed before this plugin in the plugins array for the two to work together properly. e.g.

import { babel } from '@rollup/> plugin-babel';
import commonjs from '@rollup/> plugin-commonjs';

const config = {
  ...
  plugins: [
    commonjs(),
    babel({ babelHelpers: 'bundled' })
  ],
};

In a different project bundled with rollup, I had to place commonjs() after babel(), contrary what was recommended, because otherwise I would have got a syntax error for the pipeline operator, originating from @rollup/plugin-commonjs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions