-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Upstream file not correctly recognized as output of other project when using path mappings #58156
Comments
This very much appears to be a references bug. If one comments out references in the server tsconfig.json, the issue goes away, and all expected files are compiled, but obviously the benefits of references are then negated. {
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./src",
"rootDir": "..",
"lib": ["ES2022"],
"outDir": "./dist",
"paths": {
":shared/*": [
"../../shared/src/*"
]
},
"types": [
"node"
]
},
"include": [
"src/**/*.ts",
"../shared/src/**/*.ts"
],
// "references": [
// {
// "path": "../shared"
// }
// ]
} |
This is exactly what project references is for - treating another config's files as "not part of your project" and thus not built. If the non-reference behavior is the behavior you want, then simply remove the reference. |
@RyanCavanaugh the documentation at https://www.typescriptlang.org/docs/handbook/project-references.html says: βBuild mode (see below) will automatically build the referenced project if needed By separating into multiple projects, you can greatly improve the speed of typechecking and compiling, reduce memory usage when using an editor, and improve enforcement of the logical groupings of your program.β βAdditionally, to preserve compatibility with existing build workflows, tsc will not automatically build dependencies unless invoked with the --build switchβ βRunning tsc --build (tsc -b for short) will do the following: Find all referenced projects This all seems to suggest that building is very much an expected part of references. Why would it build some files but not others? |
The expected setup for project references is that each input file corresponds to exactly one output file |
Respectfully, I donβt think that jives with what I pasted from the documentation. It also doesnβt answer the question of why it sometimes builds shared files but other times it doesnβt. What then is the point of references if it doesnβt actually build the references? Everything written seems to point to references as building referenced projects, but it seems youβre saying that isnβt the case. |
I don't know what to tell you; this feature is widely adopted, has worked this way since it shipped six years ago, and you're the first person to raise this scenario or interpret the docs that way. The scenario where the same input file ends up as multiple output files isn't supported, and having the same input file not appear in multiple outputs was a motivating scenario for why references were added in the first place. |
I think youβve misunderstood what Iβve written. Iβm saying that files specifically included in compilation by virtue of the includes field arenβt being compiled. Iβm not saying that a single input file should produce multiple output files. Help me to understand. |
Sure.
This is on purpose;
There actually is a bug here, which is that |
Thank you for helping me understand, @RyanCavanaugh. |
I've also interpreted the docs to mean that Moreover, I feel as though the solution here is to use both paths and references and pray for the best on the build ... the validity of which is unclear from the docs. |
I am going to assign this issue to myself since this is related to work i am doing in #56254 as well as the fix is more involved from build info and |
π Search Terms
"typescript not compiling single file unless in file"
π Version & Regression Information
Discovered / tested with 5.4.5.
β― Playground Link
https://github.com/TimUnderhay/ts-build-references-bug
π» Code
This is a snippet from the minimal repro repo I've created (https://github.com/TimUnderhay/ts-build-references-bug). The readme contains relevant code / reproduction details. This really can't be condensed into a snippet or playground link, as far as I can tell.
This is a reproduction of issue #44845. When using references within a monorepo to build an app that depends on a shared library reference, certain files get omitted from the tsc output for no evident reason.
The repo
Under
projects/
, there are two TS 'references', one a shared lib -- 'shared', and an app called 'server'. Server contains a reference to the shared lib, and also a path alias called:shared
, pointing to the same place.projects/server/tsconfig.json
:Steps to reproduce:
npm install
.cd projects/server
npm run build
(is justrm -rf dist/ && tsc --build -v
)projects/server/dist/shared/src
output. Notice that only the shared logging module was built. 'errors.ts' and 'global-type-overrides.ts' should be there based on the include pattern, but they aren't.π Actual behavior
Check
projects/server/dist/shared/src
output. Notice that only the shared logging module was built. 'errors.ts' and 'global-type-overrides.ts' should be there based on the include pattern, but they aren't.π Expected behavior
All modules derived from globs specified in
include
should be built.Additional information about the issue
If one builds
projects/shared
on its own, all output files are present and accounted for inprojects/shared/dist
. The issue appears to be related to references. Buildingprojects/server
with eithertsc
ortsc --build -v
appear to yield the same end result -- missing files underprojects/server/dist/shared
.It Gets Even Weirder
In
projects/server/src/server.ts
, if you uncomment the line// import { log } from ':shared/logging.js';
, the entire shared subdir gets omitted fromprojects/server/dist
!!Just. Shouldn't. Happen.
The text was updated successfully, but these errors were encountered: