admin管理员组

文章数量:1435249

One of the files under test is importing the estree-util-to-js library, which causes Jest to exit with an error:

Details:

    /.../node_modules/estree-util-to-js/index.js:8
    export { toJs } from './lib/index.js';
    ^^^^^^

    SyntaxError: Unexpected token 'export'

Curiously, I already fixed this problem once. That's why I have in my jest.config.json file the following:

{
  "preset": "ts-jest",
  "roots": ["src"],
  "testEnvironment": "jsdom",
  "transform": {
    "^.+\\.tsx?$": [
      "ts-jest",
      {
        "diagnostics": false
      }
    ],
    "^.+/estree-util-to-js/.+\\.js$": [
      "ts-jest",
      {
        "diagnostics": false
      }
    ]
  },
  "transformIgnorePatterns": ["<rootDir>/node_modules/(?!estree-util-to-js)"]
}

This worked just fine until today I upgraded lots of dependencies, after which this stopped working.

What I have managed to rule out so far:

  • estree-util-to-js was not upgraded.
  • The error also happens with plain import ...; export ... syntax, not just with export ... from;
  • Rolled back upgrade of ts-jest (29.1.2 -> 29.2.5). Didn't help.
  • No upgrade of jest itself was done.
  • Rolling back all of my package upgrades does fix the problem.

本文标签: javascriptJest failing because of importexport syntaxStack Overflow