Next.js support
See original GitHub issueIssue :
ts-jest
is not out-of-the-box compatible with Next.js
, basically because in Next.js
there is no need to add import React from "react"
in every file.
That effectively means that in ts-jest
when you import a .tsx file, all you get is 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
Expected behavior :
Work correctly out-of-the-box with Next.js
Debug log:
Test suite failed to run
TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
src/pages/index.tsx:2:13 - error TS2686: 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
2 return <div>hello world</div>
Minimal repo
I made this repo using all the expected stuff for a testing environment using testing-library https://github.com/PabloSzx/ts-jest-nextjs
Workaround
Import React in all .tsx files, even if it’s not needed for Next.js
Issue Analytics
- State:
- Created 4 years ago
- Comments:24
Top Results From Across the Web
Getting Started | Next.js
System Requirements. Node.js 14.6.0 or newer; MacOS, Windows (including WSL), and Linux are supported. Automatic Setup. We recommend creating a new Next.js ......
Read more >Supported Browsers and Features - Next.js
js supports modern browsers with zero configuration. Chrome 64+; Edge 79+; Firefox 67+; Opera 51+; Safari 12+. Browserslist.
Read more >Next.js by Vercel - The React Framework
Next.js gives you the best developer experience with all the features you need for production: hybrid static & server rendering, TypeScript support, ...
Read more >Basic Features: TypeScript - Next.js
Next.js supports TypeScript by default and has built-in types for pages and the API. You can get started with TypeScript in Next.js here....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this is not the issue with
ts-jest
because NextJs is a framework and it applies a “magic” to achieve what you describe. Makingts-jest
framework-dependent shouldn’t be done.@gabrielgrover @ahnpnl Since Typescript 4.1, there’s no more need for a transformer.
Simply add ``“jsx”: “react-jsx”… imports won’t be required anymore.
See a working example here: https://github.com/belgattitude/vercel-monorepo-test/pull/20