最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Jest failing because of importexport syntax - Stack Overflow

matteradmin2PV0评论

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.
Post a comment

comment list (0)

  1. No comments so far