`next dev` rewrites tsconfig.json
See original GitHub issueBug report
Describe the bug
When I run next dev
and some of the “required” Next.js options are missing (even non-critical ones like forceConsistentCasingInFileNames
), my tsconfig.json
is completely rewritten – my comments are deleted and the file is re-formatted.
To Reproduce
- Start
next dev
- In
tsconfig.json
, removeforceConsistentCasingInFileNames
and add some comment. - Start
next dev
again - Observe that your comment is deleted
Expected behavior
My tsconfig.json
is my tsconfig.json
😄.
System information
- OS: macOS
- Version of Next.js: 9.0.2
Additional context
This is from the “TypeScript support is too eager in v9” bucket, IMO. Some more issues I’d regard in that category are e.g. #7687 or #8065 (though they are about different things).
Issue Analytics
- State:
- Created 4 years ago
- Reactions:33
- Comments:16 (9 by maintainers)
Top Results From Across the Web
next dev rewrites tsconfig.json when it shouldn't #39942 - GitHub
Next.js will not overwrite your config every time you next build . It only checks your tsconfig.json , searches for invalid configurations that ......
Read more >Basic Features: TypeScript - Next.js
Next.js supports TypeScript by default and has built-in types for pages ... Providing your own tsconfig.json with custom compiler options is also supported....
Read more >Next.js, TypeScript and tsconfig.json 'jsx' property being ...
How to stop the jsx property being overwritten from 'react' to 'preserve' by NextJS when running the development server? My tsconfig.json file:
Read more >Documentation - What is a tsconfig.json - TypeScript
The tsconfig.json file specifies the root files and the compiler options required to compile the project.
Read more >Next.js on Twitter: "In Next.js 12.3, changes to configuration ...
In Next.js 12.3, changes to configuration files like `.env` and `.tsconfig.json` will not require restarting your local development server.
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
isolatedModules
is certainly debatable – for example, we’d like to make a tradeoff between performance and safety in our case. (Next+TS can run perfectly fine without this option.) It’s hard for a tool to predict all the possible circumstances and be 100% right all the time.I just don’t think that Next.js should be writing into my source files, especially as a by-product of something as innocent-looking as
next dev
. I’d prefer any of these:next dev
could validate that the configuration is correct and warn me / refuse to start if some critical config is not metnext init-tsconfig
Maybe there are some other options as well. I understand the good intent though and appreciate your effort around this!
It’s indeed the same issue as #8034, sorry for not noticing it earlier.
It’s OK for Next.js to generate new
tsconfig.json
when there is none (it’s very useful, actually) but overwriting existing files, possibly losing user’s work, is something that no tool should do, ever, IMO.It’s also debatable whether Next.js “needs” some of the things it says so, for example, I don’t think
compilerOptions.isolatedModules
is required for Babel and there are serious performance implications of having this turned on, for example, https://github.com/microsoft/TypeScript/issues/32294.What I’m trying to say: in the end, tsconfig should be user’s responsibility. It’s fine if Next.js makes reasonable suggestions or does some changes automatically in some cases, but it should be careful and conservative, IMO.