I am working on a Next.Js-TypeScript project. Everything was fine. Suddenly I get a VS Code warning that I have to write import React from “react”
in the .tsx
files where I have used Fragment (<></>
) of React. But everything was fine until yesterday. I suddenly saw this situation today. Then, I searched the internet and found that the “tsconfig.json” file contains (“jsx”:”preserve”
) by default, but if I change it to (“jsx”:”react-jsx”
) all the problems are solved. . But there is another problem here. When I start localhost or restart, immediately a message comes in the terminal, that We detected TypeScript in your project and reconfigured your tsconfig.json file for you. Strict-mode is set to false by default. The following mandatory changes were made to your tsconfig.json: - jsx was set to preserve (next.js implements its own optimized jsx transform)
. After that, the tsconfig.json file is reset as before.
This is my dependencies and devDependencies:
"dependencies": {
"@reduxjs/toolkit": "^2.2.7",
"bcryptjs": "^2.4.3",
"mongoose": "^8.7.0",
"next": "^14.2.13",
"next-auth": "^5.0.0-beta.20",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.0",
"react-icons": "^5.3.0",
"react-player": "^2.16.0",
"react-redux": "^9.1.2",
"react-simple-star-rating": "^5.1.7",
"react-toastify": "^10.0.5",
"redux-persist": "^6.0.0",
"sass": "^1.79.4"
},
"devDependencies": {
"@tailwindcss/aspect-ratio": "^0.4.2",
"@types/bcryptjs": "^2.4.6",
"@types/node": "^20.16.10",
"@types/react": "^18.3.10",
"@types/react-dom": "^18",
"@types/redux-persist": "^4.0.0",
"daisyui": "^4.12.10",
"eslint": "^8",
"eslint-config-next": "^14.2.13",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.13",
"typescript": "^5.6.2"
}
My tsconfig.json
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
NOTE: THIS ISSUE IS HAPPENING WITH TYPESCRIPT ONLY!!
2
Answers
In my case I found the solution to this strange problem. After I uninstalled the extension "JavaScript and TypeScript Nightly" from my VS Code everything was fine. Thank you so much guys
If I’m change the TypeScript Version to 5.6.2 (my workspace version & current stable) in VSCode the error is gone… When I go back to TS 5.7.0-dev.20241001 the umd global error comes back.
I would recommend to use a stable ts version, until its supported with newer ones.