You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you've updated [Next.js](https://nextjs.org/) and got the Jest test error:
12
+
13
+
```sh
14
+
npm test
15
+
```
16
+
17
+
```
18
+
Error: Jest: Failed to parse the TypeScript config file /home/runner/work/nextjs-typescript-template/nextjs-typescript-template/jest.config.ts
19
+
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/runner/work/nextjs-typescript-template/nextjs-typescript-template/node_modules/next/jest' imported from /home/runner/work/nextjs-typescript-template/nextjs-typescript-template/jest.config.ts
20
+
Did you mean to import "next/jest.js"?
21
+
at readConfigFileAndSetRootDir (/home/runner/work/nextjs-typescript-template/nextjs-typescript-template/node_modules/jest-config/build/index.js:2269:13)
22
+
at async readInitialOptions (/home/runner/work/nextjs-typescript-template/nextjs-typescript-template/node_modules/jest-config/build/index.js:1147:13)
23
+
at async readConfig (/home/runner/work/nextjs-typescript-template/nextjs-typescript-template/node_modules/jest-config/build/index.js:918:7)
24
+
at async readConfigs (/home/runner/work/nextjs-typescript-template/nextjs-typescript-template/node_modules/jest-config/build/index.js:1168:26)
25
+
at async runCLI (/home/runner/work/nextjs-typescript-template/nextjs-typescript-template/node_modules/@jest/core/build/index.js:1393:7)
26
+
at async Object.run (/home/runner/work/nextjs-typescript-template/nextjs-typescript-template/node_modules/jest-cli/build/index.js:656:9)
27
+
```
28
+
29
+
## Solution
30
+
31
+
The fix is that you need to replace `next/jest` with `next/jest.js` if you're using [TypeScript](https://nextjs.org/docs/app/guides/testing/jest#manual-setup):
32
+
33
+
```diff
34
+
// jest.config.ts
35
+
import type { Config } from 'jest'
36
+
-import nextJest from 'next/jest'
37
+
+import nextJest from 'next/jest.js'
38
+
```
39
+
40
+
See [example](https://github.com/remarkablemark/nextjs-typescript-template/commit/8faa647090427fcf7bc5ae4736b97b1fef1f1ab2).
0 commit comments