Skip to content

[ivy] lazy loaded modules can not be found / imported #28866

Closed

Description

@khaledosman

🐞 bug report

Affected Package

Not sure

Is this a regression?

Yes, the previous version in which this bug was not present was: 7.2.5

Description

Running the project with lazily loaded routes/modules creates a runtime error


core.js:5253 ERROR Error: Uncaught (in promise): Error: Cannot find module './x/x.module.ngfactory'
Error: Cannot find module './x/x.module.ngfactory'

The routes/paths are setup correctly as downgrading to 7.2.5 and removing ivy-ngcc from the postinstall script fixes the issue

🔬 Minimal Reproduction

https://github.com/khaledosman/advanced-angular-features-demo

  1. npm i && npm start

🌍 Your Environment

Angular Version:


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 8.0.0-beta.1
Node: 11.9.0
OS: darwin x64
Angular: 8.0.0-beta.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.14.0-beta.1
@angular-devkit/build-angular     0.13.2
@angular-devkit/build-optimizer   0.13.2
@angular-devkit/build-webpack     0.13.2
@angular-devkit/core              8.0.0-beta.1
@angular-devkit/schematics        8.0.0-beta.1
@angular/cli                      8.0.0-beta.1
@angular/elements                 7.2.5
@angular/pwa                      0.14.0-beta.1
@ngtools/webpack                  7.3.2
@schematics/angular               8.0.0-beta.1
@schematics/update                0.14.0-beta.1
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.29.0

Activity

  1. gkalpak commented on Feb 20, 2019

    @gkalpak
    Member

    Are you trying to use the experimental ivy?

  2. added this to the needsTriage milestone on Feb 20, 2019
  3. khaledosman commented on Feb 20, 2019

    @khaledosman
    Author

    yup

  4. gkalpak commented on Feb 20, 2019

    @gkalpak
    Member

    So, your app is not configured for ivy correctly. Since you don't seem to have used the --experimental-ivy cli option (which automatically takes care of things for you, you need to make some manual adjustments. See #28569 for more details.

    Once you do that, there is still an error about JIT compilation, but it is really hard to debug with so much going on in the app. (It could also be an @angular/cli issue.)
    I suggest you remove all extra modules/features and start adding them one by one until the error comes up; in other words build a minimal reproduction.

    Closing for now, but please do open a new issue (with a minimal reproduction 🙏) if you determine there is a bug in using ivy.

  5. khaledosman commented on Feb 21, 2019

    @khaledosman
    Author

    setting "aot":true in my angular.json build and "enableIvy":true in my tsconfig.app.json still didn't really fix the problem, its the same error except now its generated in the console at build time due to AoT.

    first, I got another error that was not there before

    ERROR in : Template parse errors:
    The pipe 'async' could not be found ("argin:3px;" (click)="increment()">Increment</button>
        <div style="margin:3px;">Current Count: {{ [ERROR ->]counter | async }}</div>
        <button style="margin:3px;" (click)="decrement()">Decrement</button>
       "): /Users/khaledosman/Documents/github/advanced-angular-demo/client/src/app/redux/redux.component.ts.ReduxComponent.html@3:47
    

    because it couldn't get the async pipe... Then I commented out the div that's using the async pipe to see if the actual problem was fixed, then I got the module not found error again but now on compilation time instead due to AoT

    ERROR in ./src/$$_lazy_route_resource lazy namespace object
    Module not found: Error: Can't resolve '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/app/chat/chat.module.ngfactory.js' in '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/$$_lazy_route_resource'
    ERROR in ./src/$$_lazy_route_resource lazy namespace object
    Module not found: Error: Can't resolve '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/app/css-variables-sandbox/css-variables-sandbox.module.ngfactory.js' in '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/$$_lazy_route_resource'
    ERROR in ./src/$$_lazy_route_resource lazy namespace object
    Module not found: Error: Can't resolve '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/app/react/react.module.ngfactory.js' in '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/$$_lazy_route_resource'
    ERROR in ./src/$$_lazy_route_resource lazy namespace object
    Module not found: Error: Can't resolve '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/app/redux/redux.module.ngfactory.js' in '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/$$_lazy_route_resource'
    ERROR in ./src/$$_lazy_route_resource lazy namespace object
    Module not found: Error: Can't resolve '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/app/sw-sandbox/sw-sandbox.module.ngfactory.js' in '/Users/khaledosman/Documents/github/advanced-angular-demo/client/src/$$_lazy_route_resource'
    

    this is literally a demo app, I don't know how more minimal than that it can get, there're no external dependencies in the app besides ngRx and socket.io, everything else is typical angular dependencies.

    Its a problem with lazyloading and ivy, Everything works fine if I get-rid of lazyloading and load the modules upfront. And lazy-loading works fine if I opt-out of ivy and downgrade my angular versions.

  6. gkalpak commented on Feb 21, 2019

    @gkalpak
    Member

    You also need to add "allowEmptyCodegenFiles": true in angularCompilerOptions in tsconfig.app.json. This is a temporary workaround and should not be necessary soon.
    I thought this was mentioned in #28569 (maybe it used to, but I don't see it now 😕).

  7. khaledosman commented on Feb 21, 2019

    @khaledosman
    Author

    That actually fixed it, thanks!

  8. angular-automatic-lock-bot commented on Sep 14, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions