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

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

Open
geoffreytools opened this issue Oct 17, 2021 · 0 comments
Open

Comments

@geoffreytools
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant