nx icon indicating copy to clipboard operation
nx copied to clipboard

Importing standalone components from lib into other lib's module breaks build

Open TomTomB opened this issue 3 years ago • 1 comments

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:

TomTomB avatar Aug 04 '22 16:08 TomTomB

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.

Coly010 avatar Aug 09 '22 10:08 Coly010

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.

TomTomB avatar Aug 11 '22 09:08 TomTomB

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.

github-actions[bot] avatar Mar 22 '23 02:03 github-actions[bot]