-
Notifications
You must be signed in to change notification settings - Fork 248
Description
With what library do you have an issue?
native-federation
Reproduction of the bug/regression with instructions
Reproduction Repo
See this minimum reproduction repo:
https://github.com/jaxcksn/nf-ignore-unused-deps-bug-repro
I added root package.json so you should just be able to run npm run setup and then npm run start:host from that repo root to get started.
Step by Step
- Setup a native federation remote and host angular projects, plus a shared angular component library, all children of a root folder:
If you use the angular CLI, you can scaffold it with:
mkdir repro
cd repro
ng new host
ng new remote
ng new shared --no-create-application
cd shared
ng generate library sharedAnd then setup native federation in host and remote using the angular CLI.
You should end up with something like this:
root/
├─ host/
│ ├─ angular.json
│ ├─ tsconfig.json
│ ├─ ...
│ ├─ federation.config.js
├─ remote/
│ ├─ angular.json
│ ├─ tsconfig.json
│ ├─ .,.
│ ├─ federation.config.js
├─ shared/
│ ├─ ...
│ ├─ projects/shared/src/
│ │ ├─public-api.ts
│ ├─ angular.json
- In the host and remote
tsconfig.jsonadd the following path mapping:
"compilerOptions": {
"paths": {
"shared": [
"../shared/projects/shared/src/public-api.ts"
]
}
}- Setup the host and remote
federation.config.jslike so:
const { withNativeFederation, shareAll } = require('@angular-architects/native-federation/config');
module.exports = withNativeFederation({
name: 'Host',
shared: {
...shareAll({ singleton: true, strictVersion: true, requiredVersion: 'auto' }),
},
skip: ['rxjs/ajax', 'rxjs/fetch', 'rxjs/testing', 'rxjs/webSocket'],
features: {
ignoreUnusedDeps: true,
},
sharedMappings: ['shared'],
});- Import something from the shared library in the host and remote:
import { sharedValue } from 'shared';- Try to serve/build the host or remote application:
ng serve
You should see an error like so:
An unhandled exception occurred: C:\repro\shared\projects\shared\src\util\index.ts is outside of root C:\repro\hostand then in the angular log, it'll show something like:
[error] Error: C:\repro\shared\projects\shared\src\util\index.ts is outside of root C:\repro\host
at traverseFilesystem (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\file-info\traverse-filesystem.js:85:27)
at traverseFilesystem (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\file-info\traverse-filesystem.js:107:36)
at traverseFilesystem (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\file-info\traverse-filesystem.js:107:36)
at traverseFilesystem (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\file-info\traverse-filesystem.js:107:36)
at traverseFilesystem (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\file-info\traverse-filesystem.js:107:36)
at traverseFilesystem (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\file-info\traverse-filesystem.js:107:36)
at generateUnassignedFileInfo (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\file-info\generate-unassigned-file-info.js:19:67)
at parseProject (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\main\parse-project.js:14:95)
at init (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\main\init.js:31:52)
at getProjectData (C:\repro\host\node_modules\@softarc+sheriff-core@0.19.2_typescript@5.9.3\node_modules\@softarc\sheriff-core\src\lib\api\get-project-data.js:34:41)If you set ignoreUnusedDeps to false in the federation.config.js files, the build works as expected.
> ng build
INFO Building federation artefacts
INFO Preparing shared npm packages for the platform browser
NOTE This only needs to be done once, as results are cached
NOTE Skip packages you don't want to share in your federation config
Initial chunk files | Names | Raw size | Estimated transfer size
polyfills-G7GBCUTJ.js | polyfills | 36.72 kB | 11.96 kB
main-IX3NDLRZ.js | main | 2.81 kB | 1.19 kB
chunk-2NFLSA4Y.js | - | 449 bytes | 449 bytes
styles-5INURTSO.css | styles | 0 bytes | 0 bytes
| Initial total | 39.98 kB | 13.60 kB
Lazy chunk files | Names | Raw size | Estimated transfer size
chunk-OS7HOA66.js | bootstrap | 20.19 kB | 5.31 kB
Application bundle generation complete. [1.351 seconds] - 2025-12-31T19:45:07.894Z
Expected behavior
The build would succeed with this folder and project structure with ignoredUnusedDeps set to true.
Versions of Native/Module Federation, Angular, Node, Browser, and operating system
Native Federation: 21.0.3
Angular: 21.0.6
Node: 24.11.1
Browser: N/A
Operation system: Windows 11
Other information
This structure worked with module federation.
I understand that is partially a result of our folder structure, with each project having it's own workspace, but we kind of have to do it this way due to tooling and it's a common way to setup projects with the angular CLI.
This isn't urgent, as the workaround is to disable ignoreUnusedDeps but it's a nice feature that would be nice to use in our application since we use localization.
I would be willing to submit a PR to fix this issue
- Yes
- No