Comments (9)
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"
// }
// ]
}
from typescript.
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.
from typescript.
@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
Detect if they are up-to-date
Build out-of-date projects in the correct orderâ
This all seems to suggest that building is very much an expected part of references. Why would it build some files but not others?
from typescript.
The expected setup for project references is that each input file corresponds to exactly one output file
from typescript.
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.
from typescript.
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.
from typescript.
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.
from typescript.
Sure.
shared
builds shared/src/errors.ts
to shared/dist/src/errors.js
. The is the first output
server
also includes this file, but it's recognized as an input of another project, so it's not built. This would have been the second output of shared/src/errors.ts
This is on purpose; tsc --explainFiles
talks about it:
../shared/dist/src/global-type-overrides.d.ts
Imported via ':shared/global-type-overrides.js' from file 'src/server.ts'
Matched by include pattern '../shared/src/**/*.ts' in 'tsconfig.json'
File is output of project reference source '../shared/src/global-type-overrides.ts'
File is ECMAScript module because '../shared/package.json' has field "type" with value "module"
../shared/dist/src/errors.d.ts
Imported via ':shared/errors.js' from file 'src/server.ts'
Matched by include pattern '../shared/src/**/*.ts' in 'tsconfig.json'
File is output of project reference source '../shared/src/errors.ts'
File is ECMAScript module because '../shared/package.json' has field "type" with value "module"
src/server.ts
Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
File is ECMAScript module because 'package.json' has field "type" with value "module"
../shared/src/logging.ts
Matched by include pattern '../shared/src/**/*.ts' in 'tsconfig.json'
File is ECMAScript module because '../shared/package.json' has field "type" with value "module"
There actually is a bug here, which is that logging.ts
should have been identified as an output of the referenced project, but wasn't. The emit of server/dist/shared/src/logging.js
is a bug; it shouldn't have been produced
from typescript.
Thank you for helping me understand, @RyanCavanaugh.
from typescript.
Related Issues (20)
- ESNext Set methods HOT 1
- isolatedDeclarations should not have warning for functions that have no return statements HOT 4
- Trivia ownership documentation seems to be incorrect
- `--isolatedDeclarations` allows generator functions HOT 1
- Allow `--noCheck` on the CLI with top-level `--build`
- Union in template literal simplifying unexpectedly HOT 5
- Default import from an ESM package into a CommonJS project with esModuleInterop is faulty HOT 3
- Watch cannot handle large amount of file changes HOT 1
- generator next type should be inferred as union (instead of intersection) of yields' types OR just unknown
- Elementwise elaboration fails to be found for properties mixed with incompatible index signatures using intersections
- Error when accessing properties on `globalThis` with the same name of a global variable
- [NewErrors] 5.5.0-dev.20240428 vs 5.4.5 HOT 49
- Private class properties prevent `Readonly` type inference HOT 2
- [ServerErrors][TypeScript] 5.5.0-dev.20240428 HOT 12
- [ServerErrors][JavaScript] 5.5.0-dev.20240428 HOT 9
- Strange runtime caching bug involving `as const` and `const T` generic HOT 1
- When relatively importing a `.d.ts` file in a declaration file, TypeScript loads a `.ts` file instead HOT 7
- Calling decorators with @ loses type safety with function as argument HOT 2
- Include error maps in the typescript libraries for web apis to give developers easy access to potential thrown exceptions HOT 5
- jsdoc @type does not resolve a type
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.