angular-cli: bug(commonjs): erroneous ngfactory

Bug Report or Feature Request (mark with an x)

- [x] bug report
- [ ] feature request

Versions.

@angular/cli: 1.5.0-beta.2
node: 8.6.0
os: darwin x64
@angular/animations: 5.0.0-rc.0
@angular/cdk: 2.0.0-beta.11
@angular/common: 5.0.0-rc.0
@angular/compiler: 5.0.0-rc.0
@angular/core: 5.0.0-rc.0
@angular/forms: 5.0.0-rc.0
@angular/http: 5.0.0-rc.0
@angular/material: 2.0.0-beta.11
@angular/platform-browser: 5.0.0-rc.0
@angular/platform-browser-dynamic: 5.0.0-rc.0
@angular/platform-server: 5.0.0-rc.0
@angular/router: 5.0.0-rc.0
@angular/cli: 1.5.0-beta.2
@angular/compiler-cli: 5.0.0-rc.0
@angular/language-service: 5.0.0-rc.0
typescript: 2.5.3

Repro steps.

  1. Clone the sample repo found here
  2. Change into the cli directory
  3. Run npm install and npm run build:dynamic

To show the second type of error (detailed below):

  1. After the steps above, remove MatCardModule from app.module.ts, and remove the reference to <mat-card> in app.component.ts.
  2. Run npm run build:dynamic && npm run serve:dynamic (which should succeed this time)
  3. Navigate to localhost:4000. Disable JavaScript and reload the page
  4. Attempt to navigate to the lazy route, examine the server for the error log

To show the third type of error (detailed below):

  1. Re-enable JavaScript on localhost:4000 and reload the page
  2. Attempt to navigate to the lazy route, examine the browser console for the error log

The log given by the failure.

ERROR in ./dist/server/main.bundle.js
Module not found: Error: Can't resolve '@angular/material/card/typings/index.ngfactory' in '/Users/main/universal-cli-bug/cli/dist/server'
 @ ./dist/server/main.bundle.js 1:2433-2490
 @ ./prerender.ts

Desired functionality.

AOT compilation needs to work for commonjs bundling where the bundle includes a lazy-loaded module that also includes an external module like Angular Material.

Mention any other details that might be useful.

This is an issue only when the external module is included in a lazy-loaded module. If it’s included at the top-level, it works as expected. It also works as expected in cli@1.4.4

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 19 (17 by maintainers)

Most upvoted comments

Can reproduce the server issue with Angular rc.6 and CLI 1.5 RC.3 and universal-starter repo.

LAZY_MODULE_MAP generated inside the server bundle has reference to the Module instead of the NgModuleFactory - causing factory.create to be undefined.

Please follow the discussion over the other issue, as this is an issue from Angular’s own ngc, which has a fix already in flight. Thanks!

@Toxicable To be clear, this is when you import an Angular Material module into any NgModule (lazy-loaded or otherwise). You can use my sample repo as a starter. The error has not changed from the one initially posted.

We have a separate fix for lazy modules in ng5. The problem is that making it work for ng5 seems to break ng4 so we’ll do another RC with this fix whren it’s ready (today hopefully)

Some sub issues should be fixed with #8188