-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
π Search Terms
"typescript not compiling single file unless in file"
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about building
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
:
{
"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"
}
]
}
Steps to reproduce:
- From repo root, run
npm install
. cd projects/server
npm run build
(is justrm -rf dist/ && tsc --build -v
)- 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.
π 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 in projects/shared/dist
. The issue appears to be related to references. Building projects/server
with eithertsc
or tsc --build -v
appear to yield the same end result -- missing files under projects/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 from projects/server/dist
!!
Just. Shouldn't. Happen.