Dynamic Module Federation, Angular: toSignal is not working when calling the remote application within the host application
Current Behavior
The angular toSignal function is not working when calling the remote application within the host application using dynamic module federation.
Error: NG0203: toSignal() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with runInInjectionContext. Find more at https://v21.angular.dev/errors/NG0203
https://v21.angular.dev/errors/NG0203
Expected Behavior
The angular toSignal function should work when calling the remote application within the host application using dynamic module federation.
GitHub Repo
https://github.com/hornf-nrg/my-angular-workspace-22-4-test
Steps to Reproduce
npm installrm -rf libs apps/*./node_modules/.bin/nx generate @nx/angular:host --directory=apps/host --bundler=webpack --e2eTestRunner=none --unitTestRunner=none --style=scss --remotes=remote --dynamic=true./node_modules/.bin/nx serve host --devRemotes=remote- check applications
- http://localhost:4200 (host standalone works)
- http://localhost:4200/remote (remote over host works)
- http://localhost:4201 (remote standalone works)
- quit serve command with ctrl + c
- execute the following command
cat <<EOF > apps/remote/src/app/remote-entry/entry.ts
import { Component } from '@angular/core';
import { NxWelcome } from './nx-welcome';
import { toSignal } from '@angular/core/rxjs-interop';
import { of } from 'rxjs';
@Component({
imports: [NxWelcome],
selector: 'app-remote-entry',
template: \`
<div style="color: red; font-size: xx-large; text-align: center;">
{{ testSignal() }}
</div>
<app-nx-welcome></app-nx-welcome>
\`,
})
export class RemoteEntry {
protected readonly testSignal = toSignal(of('Hello World!'));
}
EOF./node_modules/.bin/nx serve host --devRemotes=remote
- http://localhost:4200 (host standalone works)
- http://localhost:4200/remote (remote over host fails with the following error)
Error: NG0203: toSignal() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with runInInjectionContext. Find more at https://v21.angular.dev/errors/NG0203 - http://localhost:4201 (remote standalone works)
- quit serve command with ctrl + c
Nx Report
Node : 24.13.0
OS : darwin-arm64
Native Target : aarch64-macos
npm : 11.8.0
daemon : Available
nx : 22.4.0
@nx/js : 22.4.0
@nx/eslint : 22.4.0
@nx/workspace : 22.4.0
@nx/angular : 22.4.0
@nx/jest : 22.4.0
@nx/devkit : 22.4.0
@nx/esbuild : 22.4.0
@nx/eslint-plugin : 22.4.0
@nx/module-federation : 22.4.0
@nx/node : 22.4.0
@nx/playwright : 22.4.0
@nx/rspack : 22.4.0
@nx/vite : 22.4.0
@nx/vitest : 22.4.0
@nx/web : 22.4.0
@nx/webpack : 22.4.0
@nx/docker : 22.4.0
typescript : 5.9.3
---------------------------------------
Registered Plugins:
@nx/playwright/plugin
@nx/eslint/plugin
@nx/docker
@nx/vite/plugin
@nx/vitest
---------------------------------------
Community plugins:
@analogjs/vite-plugin-angular : 2.2.0
@analogjs/vitest-angular : 2.2.0
angular-eslint : 21.1.0
---------------------------------------
Cache Usage: 0.00 B / 92.64 GBFailure Logs
Error: NG0203: toSignal() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`. Find more at https://v21.angular.dev/errors/NG0203Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
We are currently updating from nx version 21.1.3 to nx version 21.2.4. Before nx version 21.2.4 toSignal works as expected. We suspect that the angular injection context from the host application is not available in the remote application. We can also reproduce this behavior in nx version 22.4.5. Switching to rspack does not fix anything. So we do not think this problem is webpack specific.
Source: nrwl/nx