nx
nx copied to clipboard
Importing standalone components from lib into other lib's module breaks build
Current Behavior
The prod build breaks as sone as angular standalone components are added to another lib's ngModule via spreaded array.
Expected Behavior
This should work in the same way as e.g. spreading a (non standalone) components array into the ngModule's delarations.
Steps to Reproduce
https://github.com/TomTomB/nx-ng-standalone-comps-issue
- Clone the repo
- Run
npm install - Run
npm run ng build
Failure Logs
libs/other-lib/src/lib/other-lib.module.ts:7:12 - error NG1010: Value at position 1 in the NgModule.imports of OtherLibModule is not a reference
Value could not be determined statically.
7 imports: [CommonModule, ...STANDALONE_COMPS],
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libs/other-lib/src/lib/other-lib.module.ts:7:27
7 imports: [CommonModule, ...STANDALONE_COMPS],
~~~~~~~~~~~~~~~~~~~
Unable to evaluate an invalid expression.
Environment
Node : 16.13.0
OS : win32 x64
npm : 8.1.3
nx : 14.5.2
@nrwl/angular : 14.5.2
@nrwl/cypress : 14.5.2
@nrwl/detox : Not Found
@nrwl/devkit : 14.5.2
@nrwl/eslint-plugin-nx : 14.5.2
@nrwl/express : Not Found
@nrwl/jest : 14.5.2
@nrwl/js : 14.5.2
@nrwl/linter : 14.5.2
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.5.2
@nrwl/web : 14.5.2
@nrwl/workspace : 14.5.2
typescript : 4.7.4
---------------------------------------
Community plugins:
This appears to be an issue with ng-packagr (https://github.com/ng-packagr/ng-packagr).
It may be worth raising the issue on their repo instead. I even tried the documentation listed on the Angular docs relating to this topic and it also seems to be incorrect: https://github.com/ng-packagr/ng-packagr
If you try this without buildable libs (omit the --buildable flag), then it works fine.
Possible workaround for now: Add all of lib's standalone components to it's NgModule's imports & exports array. Importing this module into other modules works like it did before standalone components.
I'll get this issue over to ng-packagr, thanks.
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.