Conversation
d698d04 to
46250df
Compare
46250df to
a6c3d2e
Compare
#2025) Root cause: ts-node's register() was called with compilerOptions.moduleResolution='node', which silently overrides the user's tsconfig setting. When a user sets moduleResolution to 'bundler' (required by Angular's subpath exports like `@angular/core/primitives/di`), TypeScript would still run with 'node' resolution — causing TS2307 errors because 'node' resolution cannot find packages accessed only via the package.json exports field. Fix: remove the moduleResolution override entirely. TypeScript explicitly allows moduleResolution:bundler with module:CommonJS — this combination type-checks using bundler semantics (respects package.json exports field) while still emitting CommonJS output, which is what the Angular CLI CJS process requires. All other moduleResolution values (node, node16, nodenext) also continue to work as before. The remaining overrides are kept: - module: 'CommonJS' — required, Angular CLI runs in a CJS process - types: ['node'] — gives webpack configs access to Node.js globals Adds integration test: a new 'bundler-resolution-ts' angular.json configuration in full-cycle-app uses a TS webpack config that imports from `@angular/core/primitives/di` — a subpath export with no physical file on disk. This only resolves with moduleResolution:bundler, so it fails on the old code and passes on the fix. The test is registered in integration.js so it runs automatically in CI.
a6c3d2e to
b0d1451
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a user sets
moduleResolution: "bundler"in theirtsconfig.json, the custom-webpack builder was silently overriding it with"node"insidets-node'sregister()call. This caused TypeScript to fail resolving packages that are only accessible via thepackage.jsonexportsfield (subpath exports), producingTS2307: Cannot find moduleerrors.Example:
@angular/core/primitives/dihas no physical file on disk — it is only accessible via theexportsfield. WithmoduleResolution: "bundler"it resolves fine; with"node"it does not.Reported in #2025.
Root Cause
In
packages/common/src/load-module.ts,_tsNodeRegister()passescompilerOptions.moduleResolution: 'node'tots-node. This overrides whatever the user set in theirtsconfig.json, regardless of their intent.Fix
Remove the
moduleResolutionoverride entirely. TypeScript explicitly allowsmoduleResolution: "bundler"together withmodule: "CommonJS"— the combination type-checks using bundler resolution semantics (respectsexportsfield) while emitting CommonJS output for the Node.js process.Regression Test
Adds a new
bundler-resolution-tsangular.json configuration infull-cycle-appthat uses a TypeScript webpack config importing from@angular/core/primitives/di(a subpath export, no physical file). The integration testts-config-bundler-module-resolutioninintegration.jsverifies thatng build -c bundler-resolution-tssucceeds. This fails before the fix and passes after.Previously attempted
An earlier iteration replaced
ts-nodewithtsx. This was reverted becausetsxuses esbuild for transpilation and skips TypeScript's type checker entirely — a regression for users who choose.tsconfig files specifically for type safety.Fixes #2025