TypeScript: tsconfig noEmit error: Cannot reference tsconfig if it extends other tsconfig.
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
đ Expected behavior
đ€ Other info
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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 16 (5 by maintainers)
Commits related to this issue
- https://github.com/microsoft/TypeScript/issues/49844#issuecomment-1180585460 — committed to ZerdoX-x-issue-reproducer/microsoft-TypeScript-49844 by ZerdoX-x 2 years ago
- fix: TS project references need to be able to reference .d.ts files https://github.com/microsoft/TypeScript/issues/49844#issuecomment-1180585460 — committed to CodeExpertETH/CodeExpertSync by grossbart a year ago
This issue has been marked âWorking as Intendedâ and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No
add
in base config get rid of the error message
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.Nice.
@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 -rfcommand 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?
That doesnât really answer my question, I guess.
Referencing a project does the following:
.tsfiles to their corresponding.d.tsfiles (undernoEmit, those .d.ts files donât exist)tsc -bto rebuild the upstream project if itâs out of date (if it doesnât emit, this question doesnât make any sense)outFileto the current project (undernoEmit, those .d.ts files donât exist)Solution for us was to configure a base
tsconfig.jsonwithfilesas an empty array:Then the error message
Referenced project may not disable emitgoes away.Check out some examples:
@typescript-eslint/*packages https://github.com/typescript-eslint/typescript-eslint/issues/2094#issuecomment-1820936720In my head the ideal solution is just having an option to make
tscjust 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 đ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-configurationfolder.