Skip to content

[Bug]: @babel/eslint-parser doesn't work with an ESM babel config file #13352

@ghost

Description

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/eslint-parser

Input code

.eslintrc.json:

{
  "env": {
    "shared-node-browser": true,
    "es2021": true
  },
  "extends": ["eslint:recommended", "airbnb-base", "prettier"],
  "overrides": [
    // [...]
  ],
  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "sourceType": "module",
    "ecmaFeatures": {
      "impliedStrict": true
    }
  },
  "plugins": ["@babel", "..."],
  "root": true,
  "rules": {
    // [...]
  }
}

Configuration file name

babel.config.js

Configuration

babel.config.js (in a type=module project):

export default {
  targets: {
    esmodules: true,
  },
  sourceType: 'module',
  babelrc: false,
  presets: [
    // [...]
  ],
  plugins: [
    // [...]
  ],
};

Current and expected behavior

Expected behavior: @babel/eslint-parser successfully reads in my ESM config file
Actual behavior: Eslint throws an error complaining about the babel config file not being imported asynchronously (Parsing error: <path>/babel.config.js: Error while loading config - You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously)

Environment

  • OS: Arch GNU/Linux with kernel version 5.12 (rolling release)
  • Package manager: pnpm (6.4.0) via node v16.2.0
  • Monorepo: No (single babel.config.js file in root)
  • Packages:
@babel/cli: 7.13.16
@babel/core: 7.14.2
@babel/eslint-parser: 7.14.2
@babel/eslint-plugin: 7.13.16
eslint: 7.26.0

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: eslintoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions