question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tsconfig path should be configurable

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
tamj0rd2commented, Dec 23, 2020

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.

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

1reaction
attila9654commented, Dec 17, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
All relative paths found in the configuration file will be resolved relative to the configuration file they originated in.
Read more >
How to use paths in tsconfig.json? - Stack Overflow
So Typescript config file have answer for the same. Just specify the baseUrl, config will take care of your relative path. way to...
Read more >
Setting up Path Alias in TypeScript and tsc build without error
This is how I setup path alias for my projects​​ Third, go to tsconfig. json and add the paths alias options inside compilerOptions....
Read more >
tsconfig-paths - npm
The typescript compiler can resolve these paths from tsconfig so it will compile OK. But if you then try to execute the compiled...
Read more >
Use `@scope` Paths for Shorter Import Paths Configurable in ...
Relative import paths in large applications can quickly become difficult, and well, long. To avoid long and difficult relative import paths ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found