Typescript: noEmit can't be negated in extended tsconfig.json files

Created on 21 Feb 2020  路  2Comments  路  Source: microsoft/TypeScript


TypeScript Version: 3.8.2


Search Terms: Option 'noEmit' cannot be specified with option 'incremental'

Code

I am trying to compile a Nextjs app that is part of a bigger monorepo with different compile targets. Although it technically uses webpack, not tsc, the error originates from TypeScript, and the error message seems to imply that it is now ts-loader's responsibility to remove the option altogether, rather than pass a valid combination, which seems wrong.

e.g. the NextJS project's tsconfig.json

{
  "extends": "../tsconfig.client.json",
  "compilerOptions": {
    "composite": false,
    "declaration": false,
    "allowJs": true,
    "noEmit": false,
    "isolatedModules": true
  },
  "exclude": ["node_modules"],
  "include": ["next-env.d.ts", "next.config.js", "./**/*.ts", "./**/*.tsx"],

The ../tsconfig.client.json in that

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "composite": true,
    "target": "es5",
    "module": "esnext",
    "lib": ["dom", "dom.iterable", "esnext"],
    "skipLibCheck": true,
    "jsx": "preserve"
  }
}

and the ../tsconfig.json in that is:

{
  "compilerOptions": {
    "strict": true,
    "incremental": true,
    "composite": true,
    "noEmit": true
}

Expected behavior:

As was the case in 3.7 and earlier, because in the innermost level, noEmit is false, the build should proceed, since the set of options is valid.

Actual behavior:

Upon calling "next build", I get

ERROR in C:/Projects/monorepo/client/app1/tsconfig.json(7,5):
7:5 Option 'noEmit' cannot be specified with option 'incremental'.
     5 |     "declaration": false,
     6 |     "allowJs": true,
  >  7 |     "noEmit": false,
       |     ^
     8 |     "isolatedModules": true
     9 |   },
    10 |   "exclude": ["node_modules"],

> Build error occurred
Error: > Build failed because of webpack errors

but this error occurs only with typescript 3.8, meaning that even on a library level, if composite is in the set, noEmit must not occur at all, rather than it occuring with false being OK.

I need it to be accepted with false, since it is true at the root, I want to override it at the leaf, while still keeping the nonorepo's tsconfig files DRY.

I guess ts-loader can be adjusted to unset options if they match the current typescript version's default values, though getting such defaults seems like an error prone approach to me, as defaults may change from one TypeScript version to another.

Playground Link:

Related Issues: #36917

External

Most helpful comment

@sheetalkamat this might be something we end up putting in a patch release so please prioritize. Thanks!

All 2 comments

@sheetalkamat this might be something we end up putting in a patch release so please prioritize. Thanks!

This seems issue with the ts-loader instead.. I don't see error with noEmit true at all when I run with tsc

c:\temp\test2\client>type tsconfig.json
{
  "extends": "../tsconfig.client.json",
  "compilerOptions": {
    "composite": false,
    "declaration": false,
    "allowJs": true,
    "noEmit": false,
    "isolatedModules": true
  },
  "exclude": ["node_modules"],
  "include": ["next-env.d.ts", "next.config.js", "./**/*.ts", "./**/*.tsx"],
}
c:\temp\test2\client>type ..\tsconfig.client.json
{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "composite": true,
    "target": "es5",
    "module": "esnext",
    "lib": ["dom", "dom.iterable", "esnext"],
    "skipLibCheck": true,
    "jsx": "preserve"
  }
}
c:\temp\test2\client>type ..\..\tsconfig.json
{
  "compilerOptions": {
    "strict": true,
    "incremental": true,
    "composite": true,
    "noEmit": true
}
}
c:\temp\test2\client>node c:\TypeScript\built\local\tsc.js
error TS5055: Cannot write file 'c:/temp/test2/client/next.config.js' because it would overwrite input file.


Found 1 error.


Was this page helpful?
0 / 5 - 0 ratings

Related issues

uber5001 picture uber5001  路  3Comments

blendsdk picture blendsdk  路  3Comments

Roam-Cooper picture Roam-Cooper  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

dlaberge picture dlaberge  路  3Comments