TypeScript: 4.8 hasSameBuildInfo can randomly crash tsc.js with "Cannot read properties of undefined (reading 'path')"
Bug Report
Multiple packages in the monorepo are being built simultaneously when this happens:
// This is where we are building each package to be published.
const results = await pMap(packagePaths, async (packagePath) => buildForNpm({ packagePath, groupName }), {
// Change to 1 and the problem seems to go away,
// but it will take significantly longer to build.
concurrency: 20
});
buildForNpm
runs tsc --build tsconfig.json --pretty
if (refBuildInfo.path === buildInfoCacheEntry.path)
^
TypeError: Cannot read properties of undefined (reading 'path')
at hasSameBuildInfo (/project/node_modules/typescript/lib/tsc.js:105509:26)
at hasSameBuildInfo (/project/node_modules/typescript/lib/tsc.js:105517:21)
at getUpToDateStatusWorker (/project/node_modules/typescript/lib/tsc.js:105453:44)
at getUpToDateStatus (/project/node_modules/typescript/lib/tsc.js:105531:22)
at getNextInvalidatedProjectCreateInfo (/project/node_modules/typescript/lib/tsc.js:105082:26)
at getNextInvalidatedProject (/project/node_modules/typescript/lib/tsc.js:105142:20)
at build (/project/node_modules/typescript/lib/tsc.js:105665:38)
at Object.build (/project/node_modules/typescript/lib/tsc.js:105863:101)
at performBuild (/project/node_modules/typescript/lib/tsc.js:106569:73)
at Object.executeCommandLine (/project/node_modules/typescript/lib/tsc.js:106514:24)
Once the problem happens, the problem will keep happening until the output in cache/outDir is deleted.
The error is thrown here: https://github.com/microsoft/TypeScript/blob/main/src/compiler/tsbuildPublic.ts#L1794
Possibly related to the changes in this PR: https://github.com/microsoft/TypeScript/pull/48784.
This fixes the problem for me. Happy to make a PR if I can figure out how to test it.
-if (refBuildInfo.path === buildInfoCacheEntry.path) return true;
+if (refBuildInfo?.path === buildInfoCacheEntry.path) return true;
🔎 Search Terms
- Parallel builds.
- Concurrent builds.
- race condition.
- randomly failing to build.
🕗 Version & Regression Information
- TypeScript 4.8.2
- This is a crash.
- This changed between versions 4.7 and 4.8.2
⏯ Playground Link
Not able to reproduce with small projects.
💻 Code
This is happening in a large closed-source project.
🙁 Actual behavior
Crashing during build.
🙂 Expected behavior
No crash.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (11 by maintainers)
Commits related to this issue
- Check if its same buildinfo only for directly referenced projects and not recursively Fixes #50545 — committed to microsoft/TypeScript by sheetalkamat 2 years ago
- Cherry-pick PR #50617 into release-4.8 Component commits: 83a58b0229 Check if its same buildinfo only for directly referenced projects and not recursively Fixes #50545 — committed to typescript-bot/TypeScript by sheetalkamat 2 years ago
- Check if its same buildinfo only for directly referenced projects and not recursively (#50617) Fixes #50545 — committed to microsoft/TypeScript by sheetalkamat 2 years ago
- Cherry-pick PR #50617 into release-4.8 (#50618) Component commits: 83a58b0229 Check if its same buildinfo only for directly referenced projects and not recursively Fixes #50545 Co-authored-by: Sh... — committed to microsoft/TypeScript by typescript-bot 2 years ago
- Update dependency typescript to v4.9.4 (#1642) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [typescript](https://www.typescriptlang.org/) ([source... — committed to Calciumdibromid/CaBr2 by deleted user a year ago
- Update dependency typescript to v5 (#275) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [typescript](https://www.typescriptlang.org/) ([source](htt... — committed to Vylpes/vylbot-app by deleted user a year ago
@dylang thanks for all the info. i am working on the fix. But just so you know
/projects/dylang-prs/config/browserslist-config-dylang/tsconfig.json
isnt building anything… you mentioned something about javascript file being there but since you dont haveallowJs
orcheckJs
it isnt included in the project and because you have “references: []” it is treated as solution config and you arent getting any error about no files found per configuration.Here is
/projects/dylang-prs/config/browserslist-config-dylang/tsconfig.json
:It does not have any dependencies and therefor no references.