Jest - Next.js - Unexpected token error inside jest node-modules

Viewed 31

I installed jest with the following command on my next js project

npm i --save-dev jest @testing-library/react @testing-library/jest-dom jest-environment-jsdom   

then added jest.config.json file with the below code

const nextJest = require("next/jest");
const createJestConfig = nextJest({
  dir: "./",
});
const customJestConfig = {
  moduleDirectories: ["node_modules", "<rootDir>/"],
  testEnvironment: "jest-environment-jsdom",
};
module.exports = createJestConfig(customJestConfig);

Now, when I run 'npm test', I get the following error

Test suite failed to run

D:\my-project\node_modules\@jest\reporters\build\GitHubActionsReporter.js:67

  #getMessageDetails(failureMessage, config) {
                    ^

SyntaxError: Unexpected token '('

at Object. (node_modules/@jest/reporters/build/index.js:75:3)

I've tried a lot of solutions, updating the config file, adding babel plugins, none worked. And I haven't found any mention of this error online. What is the issue here?

My dev-dependencies versions -

"devDependencies": {
  "@testing-library/jest-dom": "^5.16.5",
  "@testing-library/react": "^13.4.0",
  "eslint": "8.14.0",
  "eslint-config-next": "12.1.5",
  "jest": "^29.0.3",
  "jest-environment-jsdom": "^29.0.3"
}
0 Answers
Related