Tsconfig path should be configurable
See original GitHub issueBug report
Describe the bug
Next will automatically use the root tsconfig.json as the config for its build.
Specifically problem is that it clashes with other project tooling:
-
VS Code will use this config as the source of truth, so you can’t exclude test files, Storybook stories etc. otherwise they won’t be correctly typed in the text editor
-
Next will use this config for its build, so you should exclude irrelevant files, in order to at least fasten the build even if the files will end up not being used.
To Reproduce
Install TS in an app.
{
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"baseUrl": "./",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "preserve",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": false,
"target": "es5",
"paths": {
"~/*": [
"src/*"
]
}
},
"exclude": [
"node_modules",
"**/*.stories.tsx",
"**/stories.tsx"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
}
The exclude part is conflicting, I need it to optimize Next bundle, I must remove it for VS Code to work (and VS code does not allow to configure a different tsconfig path either).
Note that the .storybook folder has a tsconfig.json that includes stories, but it does not work, VS code still respect the root tsconfig exclude.
Expected behavior
We should have a separate tsconfig.next.json file, either as a default or optionnaly, to avoid clashes with other tooling. Using the default tsconfig.json file is sadly a common practice but not realistic in a real life application.
Any other escape hatch to solve this would be welcome.
To sum it up tsconfig.json should be considered as a kind of tsconfig.common.json, that is shared by all config but optimized for none. So it should always be possible to specify it a bit more.
System information
- Version of Next.js: 9.3
Additional context
My app is setup with Jest, cypress, Storybook, Next custom server, and Next. Each environment needs a slightly different tsconfig with a shared common basis. Only Next client part do not allow configuration of the tsconfig file path.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:7 (5 by maintainers)

Top Related StackOverflow Question
But then vscode doesn’t seem to recognise all my files, since that specifically always looks for tsconfig.json. Can we please have a way to configure the path? It’d solve so many issues
You can have tsconfig.json for next.js which extends a tsconfig.common.json and other tsconfigs eg. tsconfig.jest.json which also extends the common.