Skip to content

[Bug]: Conflict between @babel/plugin-syntax-import-assertions and @babel/plugin-syntax-import-attributes in Jest tests #16754

@VictorDuarteShowpass

Description

@VictorDuarteShowpass

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

No specific code triggering the issue, but the setup is as follows:

Monorepo with React, TypeScript, and Next.js
Jest tests using babel-jest with the next/babel preset for transformation
There are no import ... assert statements in the codebase

Configuration file name

No response

Configuration

Jest Config:

module.exports = {
  transform: {
    "^.+\\.(ts|tsx)$": [
      "babel-jest",
      {
        presets: ["next/babel"],
      },
    ],
  },
  setupFilesAfterEnv: ["./test/setup-tests.ts"],
  moduleNameMapper: {
    ".+\\.(css|styl|less|sass|scss|jpg|png|ttf|woff|woff2)$": "identity-obj-proxy",
    "^.+\\.svg$": "jest-svg-transformer",
    "^@/(.*)$": "<rootDir>/$1",
  },
  snapshotSerializers: ["@emotion/jest/serializer"],
  collectCoverage: true,
  coverageDirectory: "coverage",
  testEnvironment: "jsdom",
};

Current and expected behavior

The Jest tests fail due to a conflict between @babel/plugin-syntax-import-assertions and @babel/plugin-syntax-import-attributes, despite neither of these plugins being explicitly included in the configuration.

Expected Behavior
The tests should run successfully without loading conflicting Babel plugins since no import ... assert syntax is used in the codebase.

Environment

Babel version(s): @babel/core@latest
Node/npm version: Node v18
OS: macOS/Linux
Monorepo setup with Next.js, React, TypeScript, Jest
Jest version: 29.7.0
babel-jest version: 29.7.0

Possible solution

No response

Additional context

I’ve tried the following solutions:

Downgraded Babel dependencies to previous stable versions
Cleared Jest and Babel caches
Verified that no import ... assert statements exist in the codebase
Forced resolutions in package.json to remove the conflicting plugins

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA 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