Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsconfig noEmit error: Cannot reference tsconfig if it extends other tsconfig. #49844

Closed
ZerdoX-x opened this issue Jul 9, 2022 · 16 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ZerdoX-x
Copy link

ZerdoX-x commented Jul 9, 2022

Bug Report

πŸ”Ž Search Terms

  • tsconfig.json
  • noEmit
  • extends
  • reference
  • Referenced project may not disable emit.

πŸ•— Version & Regression Information

Tried 4.8.0-beta, 4.7.3, 4.7.4, and 4.6.3

⏯ Playground Link

πŸ’» Code

Couldn't reproduce this in Bug Workbench, but here is my minimal reproduction repo:
https://github.com/ZerdoX-x-issue-reproducer/microsoft-TypeScript-49844

tsconfig.json:

{
  "references": [{ "path": "./tsconfig.test.json" }],
  "compilerOptions": {
    "noEmit": true
  }
}

tsconfig.test.json:

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "composite": true,
    "noEmit": true
  }
}

tsconfig.base.json:

{
  "include": [
    "src/**/*.d.ts",
    "src/**/*.js",
    "src/**/*.ts",
  ],
  "compilerOptions": {
    "noEmit": true,
  }
}

πŸ™ Actual behavior

image

πŸ™‚ Expected behavior

image

πŸ€” Other info

SO question

UPDATE: Since this issue keeps receiving comments and attention, I would like to let you know that I don't suffer from this issue anymore, but reproduction will be opened as long as my account exists :) Afair I was using SvelteKit and I just wanted to get proper type checking for all of my files: 1) source files which would or would not get bundled to be running on client and/or server 2) configuration files, where some files use ESM, some still support only CJS 3) tests.
In newer projects I achieve this goal and do not stumble upon this issue, also it got easier now since new ESLint flat config which will be released in next major release.

@ZerdoX-x ZerdoX-x changed the title tsconfig noEmit error: Cannot reference tsconfig if it extends with other tsconfig. tsconfig noEmit error: Cannot reference tsconfig if it extends other tsconfig. Jul 9, 2022
@Markkos89
Copy link

facing the same issue and is driving me crazy :(

@ZerdoX-x
Copy link
Author

facing the same issue and is driving me crazy :(

For me it doesn't affect anything. Just a visual error in vscode, so it's fair enough to place a comment with linking this issue above "references": (glad typescript.json is JSONC) and ignore it without remorse.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 11, 2022
@RyanCavanaugh
Copy link
Member

This configuration doesn't make any sense; every behavior of having a reference is dependent on the output files of the referenced project being present. What are you trying to achieve?

@Josh-Cena
Copy link
Contributor

Question: is there an easy way to type-check with a single tsc run, without emit, and with different sets of files using different libs? Or do we have to use multiple tsc runs?

@RyanCavanaugh
Copy link
Member

Question: is there an easy way to type-check with a single tsc run, without emit, and with different sets of files using different libs

No

@ZerdoX-x
Copy link
Author

ZerdoX-x commented Jul 11, 2022

This configuration doesn't make any sense; every behavior of having a reference is dependent on the output files of the referenced project being present. What are you trying to achieve?

Of course this configuration doesn't make any sense. Because this is not a configuration but a minimal reproduction of the issue. If you need to see my full production setup, I've added all configs to the my-full-configuration folder.

ZerdoX-x added a commit to ZerdoX-x-issue-reproducer/microsoft-TypeScript-49844 that referenced this issue Jul 11, 2022
@RyanCavanaugh
Copy link
Member

That doesn't really answer my question, I guess.

Referencing a project does the following:

  • Changes imports of .ts files to their corresponding .d.ts files (under noEmit, those .d.ts files don't exist)
  • Causes tsc -b to rebuild the upstream project if it's out of date (if it doesn't emit, this question doesn't make any sense)
  • Adds any declaration outFile to the current project (under noEmit, those .d.ts files don't exist)

@ZerdoX-x
Copy link
Author

If I don't reference tsconfig.test.json in tsconfig.json I will end up with errors like this while trying to import from $lib (alias is set in tsconfig.base.json which is inherited in tsconfig.test.json) in files which are excluded in tsconfig.json
image

And also I noticed that vscode says I don't have tsconfig loaded for this file (and that's the reason why aliases doesn't work). Is this an issue with vscode?
image

But when I do reference, vscode shows loaded tsconfig.test.json as expected for this file.

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@ZerdoX-x
Copy link
Author

Nice.

@tylim88
Copy link

tylim88 commented Dec 27, 2022

add

"include": [],
"files":[]

in base config get rid of the error message

@ITenthusiasm
Copy link

What are you trying to achieve?

@RyanCavanaugh, based on @ZerdoX-x's other comments, I'm assuming that the goal is to have type checking for test files without including them in the project's output. At least, that's what I need, and that's how I stumbled upon this issue.

TypeScript's Project Reference Documentation suggested to me that Project References were the way to handle monorepos in NPM, keep TS working with tests, and keep the test files out of the build directory simultaneously. (Developers shouldn't need to include a rm -rf command in their build step. The compiler should simply exclude all undesired files from the build output.) I haven't found any clear documentation on how to handle this use case.

If you aren't going to reopen the issue, would you be willing to give a reasonable alternative? Maybe there's something we're missing?

@ITenthusiasm
Copy link

What also might be coming out is a desire for simplicity. To expound a little more, many people want the ability to say, "Type Check my entire monorepo" in one command. But that gets difficult when there are files intended to be included in the output (regular files from several scoped packages) and files not intended to be in the output (such as test files and configuration files).

Maybe clarity on what the recommendation is for monorepos would also be helpful? My goal is to avoid getting caught up in the chaos of turborepo, yarn workspaces, etc. I just want to work with simple NPM and TS for my monorepo.

@audunolsen
Copy link

In my head the ideal solution is just having an option to make tsc just hold the necessary reference declaration output in memory or in an internally handled temporary scratch/cache dir for the entirety of the command's run without any reading or writing to the file system of the monorepo. An ever increasing size of devs are only using ts for intellisense in their IDE and as a CI test step or commit hook, no compiling. Can't really find any solution to this myself πŸ‘€

@karlhorky
Copy link
Contributor

karlhorky commented Nov 21, 2023

Solution for us was to configure a base tsconfig.json with files as an empty array:

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "files": [],
  "references": [
    { "path": "./tsconfig.root.json" },
    { "path": "./scripts/tsconfig.json" }
  ]
}

Then the error message Referenced project may not disable emit goes away.

Check out some examples:

@atollk
Copy link

atollk commented Nov 27, 2023

Came here through Google, none of the suggested solutions so far helped me out. For me, I had to add "compilerOptions": { "declaration": true }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

10 participants