angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.71k stars 11.98k forks source link

Build prod issue with lazy loaded modules specifying the "default" keyword. #5197

Closed fathert closed 5 years ago

fathert commented 7 years ago

Please provide us with the following information:

OS?

Windows 7

Versions.

@angular/cli: 1.0.0-rc.0
node: 7.5.0
os: win32 x64
@angular/common: 4.0.0-rc.2
@angular/compiler: 4.0.0-rc.2
@angular/core: 4.0.0-rc.2
@angular/forms: 4.0.0-rc.2
@angular/http: 4.0.0-rc.2
@angular/platform-browser: 4.0.0-rc.2
@angular/platform-browser-dynamic: 4.0.0-rc.2
@angular/router: 4.0.0-rc.2
@angular/cli: 1.0.0-rc.0
@angular/compiler-cli: 4.0.0-rc.2

Repro steps.

App created using Angular CLI. Running ng build prod gives the following warnings when lazy loaded modules use the "default" class keyword instead of specifying the class with the hash prefix in the route.

WARNING in ./src/$$_gendir/app/login/login.module.ngfactory.ts
73:34-53 "export 'LoginModule' (imported as 'import1') was not found in '../../../app/login/login.module'

The resulting app won't run.

The log given by the failure.

inline.c918832d67bd4200d5d3.bundle.js:1 Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
polyfills.5ae05d8a767e1cd2b570.bundle.js:1 Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
scripts.fc66e4c0d56e2edb584d.bundle.js:1 Uncaught ReferenceError: webpackJsonp is not defined
    at scripts.fc66e4c0d56e2edb584d.bundle.js:1
vendor.cd883e4d47d03df5332f.bundle.js:1 Uncaught ReferenceError: Invalid left-hand side in assignment
main.ca6936fa0c1b6ba2bf52.bundle.js:1 Uncaught ReferenceError: webpackJsonp is not defined
    at main.ca6936fa0c1b6ba2bf52.bundle.js:1

Mention any other details that might be useful.

Removing the default keyword from the module class: export default class LoginModule { }

...and using the hash notation in the route config solves the problem: { path: 'login', loadChildren: './login/login.module#LoginModule' },

Thee issue only affects prod builds.


Thanks! We'll be in touch soon.

filipesilva commented 7 years ago

@hansl can you weigh in?

hansl commented 7 years ago

Mike saw the "Uncaught Reference" error earlier, and we investigated but it just went away when nuking node_modules and reinstalling.

Default exports might not work with ngc, we need to investigate. @fathert any reason you need to use default there?

fathert commented 7 years ago

Hi there, no, there's no reason I need it, I was following a tutorial which used "default" in preference to the hash notation that's all.

Darshan-popin commented 7 years ago

+1

mgechev commented 5 years ago

@fathert can you still reproduce this issue with the latest CLI?

mgechev commented 5 years ago

Closing the issue due to inactivity. If the problem still exists in the latest version of the CLI, please open a new issue following the template and providing a minimal demo where we can reproduce it. Thanks! :-)

angular-automatic-lock-bot[bot] commented 4 years ago

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.