Skip to content

fix(schematics): drop the @schematics/angular runtime import - #123

Merged
Aukevanoost merged 4 commits into
mainfrom
fix/schematics-angular-runtime-dep
Aug 11, 2026
Merged

fix(schematics): drop the @schematics/angular runtime import#123
Aukevanoost merged 4 commits into
mainfrom
fix/schematics-angular-runtime-dep

Conversation

@Aukevanoost

Copy link
Copy Markdown
Contributor

Problem

ng g @angular-architects/native-federation:init fails on pnpm:

An unhandled exception occurred: Cannot find package '@schematics/angular' imported from
.../@angular-architects/native-federation/src/schematics/init/steps/add-dependencies.js

add-dependencies.ts imported @schematics/angular/utility/dependencies at runtime, but the package was only listed in devDependencies, so it never shipped in the published package.json. npm's flat node_modules makes it resolve by accident (@angular/cli hoists it to the top); pnpm's isolated layout does not — the package's own node_modules only contains its declared deps, and it isn't in the virtual store's hoist dir either.

Reproduces on a stock ng new app with pnpm as package manager. Affects every pnpm user running init.

Fix

Only addPackageJsonDependency and the NodeDependencyType enum were used, so rather than promoting @schematics/angular to a runtime dependency, they're replaced with a local helper following the readJson → mutate → overwrite pattern already used in update-package-json.ts and wire-serve-ssr-script.ts. The dependency is removed entirely — it was the only import site in the repo.

Semantics are unchanged (overwrite still means "replace if present"). One behavioural difference: addPackageJsonDependency used JSONFile, which edits surgically and preserves the user's formatting, whereas this rewrites the file with 2-space indent. That's already what the two steps above do in the same schematic run, so nothing is lost in practice.

Also included

4fd8430getFederationArg's --type=remote branch emitted { '<project>': './remoteEntry.json' }, so a generated remote passed a map pointing at its own remoteEntry. Now emits initFederation() with no argument. The file is also reformatted to prettier's double-quote/trailing-comma style.

Verification

check result
pnpm typecheck clean
pnpm lint 0 errors (31 pre-existing warnings)
pnpm build ok
pnpm knip clean
pnpm test 151/151 pass
grep -r @schematics/angular dist/ no hits

Note

21.x.x carries the identical bug ("@schematics/angular": "^21.2.0" in devDependencies, same single import site) — not ported here.

add-dependencies.ts imported '@schematics/angular/utility/dependencies'
at runtime, but the package was only a devDependency. npm's flat
node_modules made it resolve by accident; under pnpm's isolated layout
`ng g @angular-architects/native-federation:init` failed with
"Cannot find package '@schematics/angular'".

Only addPackageJsonDependency and NodeDependencyType were used, so
replace them with a local helper following the readJson/overwrite
pattern already used in update-package-json.ts, and remove the
dependency instead of promoting it to a runtime one.
getFederationArg's default branch (--type=remote) returned
`{ '<project>': './remoteEntry.json' }`, so a generated remote passed a
map pointing at its own remoteEntry. Return an empty arg instead.

Also reformats the file to prettier's double-quote/trailing-comma style.
@Aukevanoost
Aukevanoost merged commit 3d6dac6 into main Aug 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant