Skip to content

Getting WARNINGs in ./src/app/app.module.ngfactory.js and *lib.ngfactory.js with ng build --prod, won't happen with ng build #11394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
netpoe opened this issue Jun 28, 2018 · 8 comments

Comments

@netpoe
Copy link

netpoe commented Jun 28, 2018

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Area

- [x] devkit
- [ ] schematics

Versions

npm 6.1.0
macOS High Sierra
Angular CLI: 6.0.8
Node: 8.10.0
OS: darwin x64
Angular: 6.0.6
@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cli 6.0.8
@ngtools/webpack 6.0.8
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.2.1
typescript 2.7.2
webpack 4.8.3

Repro steps

I created an angular library ng generate library common-lib --prefix=canyalib

Added these components and services to the library module

Exported them in the public_api.ts

Used the library components successfully in the project app

The CommonLibModule is imported in the app.module.ts

Ran ng build --prod common-lib and got no errors

Packaged the library and published it to the npm registry npm run package

"scripts": {
    "build_lib": "ng build --prod common-lib",
    "npm_pack": "cd dist/common-lib && npm pack",
    "package": "npm run build_lib && npm run npm_pack"

Installed the angular library in another Angular 6 app with: npm install @canyaio/[email protected]

Added the CommonLibModule to the app.module.ts as well as in other app modules through a shared module.

I run ng serve or ng build and I get no errors. I can even deploy the app to firebase.

I run ng serve --prod or ng build --prod and:

The log given by the failure

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
 92% chunk asset optimization UglifyJSPlugin 「wdm」: wait until bundle finished: /assets/i18n/es_ES.json

Date: 2018-06-27T22:55:43.231Z
Hash: 36fd56e26b227869b568
Time: 227060ms
chunk {0} runtime.a66f828dca56eeb90e02.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.3b401f7315e1889fc196.css (styles) 184 kB [initial] [rendered]
chunk {2} polyfills.16be5397c080c6bf4c93.js (polyfills) 59.8 kB [initial] [rendered]
chunk {3} main.9918d4723eeee42a175e.js (main) 4.36 MB [initial] [rendered]

WARNING in ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
132:230-248 "export 'FooterComponent' (imported as 'i1') was not found in '@canyaio/common-lib'

WARNING in ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
133:86-104 "export 'FooterComponent' (imported as 'i1') was not found in '@canyaio/common-lib'

WARNING in ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
17:1349-1369 "export 'HttpLoaderFactory' (imported as 'i1') was not found in '@canyaio/common-lib'

WARNING in ./src/app/missing-metamask/container.component.ngfactory.js
17:1812-1830 "export 'FooterComponent' (imported as 'i3') was not found in '@canyaio/common-lib'

WARNING in ./src/app/document-index/documents-index-wrapper/documents-index-wrapper.component.ngfactory.js
28:2029-2048 "export 'FooterComponent' (imported as 'i14') was not found in '@canyaio/common-lib'

WARNING in ./src/app/document-request-signatures/documents-request-signatures-wrapper/documents-request-signatures-wrapper.component.ngfactory.js
31:2021-2040 "export 'FooterComponent' (imported as 'i17') was not found in '@canyaio/common-lib'

WARNING in ./src/app/document-sign/documents-sign-wrapper/documents-sign-wrapper.component.ngfactory.js
32:1994-2013 "export 'FooterComponent' (imported as 'i18') was not found in '@canyaio/common-lib'

WARNING in ./src/app/app.module.ngfactory.js
46:3726-3747 "export 'HttpLoaderFactory' (imported as 'i15') was not found in '@canyaio/common-lib'
「wdm」: Compiled with warnings.

Desired functionality

This error won't let me run the app with library modules in a production environment.

Mention any other details that might be useful

The library I created and I'm importing to the external app is using @ngx-translate/core and @ngx-translate/http-loader

But the problem is with the FooterComponent and HttpLoaderFactory in the WARNINGS.

Additionally. As I'm getting only WARNINGs, I can deploy my ng build --prod app to firebase, but the app won't run. The browser console is full of errors:

main.9918d4723eeee42a175e.js:1 Invalid asm.js: Unexpected token
main.9918d4723eeee42a175e.js:1 ERROR Error: StaticInjectorError(i)[e -> e]: 
  StaticInjectorError(Platform: core)[e -> e]: 
    NullInjectorError: No provider for e!
    at e.get (main.9918d4723eeee42a175e.js:1)
    at main.9918d4723eeee42a175e.js:1
    at e (main.9918d4723eeee42a175e.js:1)
    at e.get (main.9918d4723eeee42a175e.js:1)
    at main.9918d4723eeee42a175e.js:1
    at e (main.9918d4723eeee42a175e.js:1)
    at e.get (main.9918d4723eeee42a175e.js:1)
    at Ir (main.9918d4723eeee42a175e.js:1)
    at e.get (main.9918d4723eeee42a175e.js:1)
    at bi (main.9918d4723eeee42a175e.js:1)
re @ main.9918d4723eeee42a175e.js:1
main.9918d4723eeee42a175e.js:1 Error: StaticInjectorError(i)[e -> e]: 
  StaticInjectorError(Platform: core)[e -> e]: 
    NullInjectorError: No provider for e!
    at e.get (main.9918d4723eeee42a175e.js:1)
    at main.9918d4723eeee42a175e.js:1
    at e (main.9918d4723eeee42a175e.js:1)
    at e.get (main.9918d4723eeee42a175e.js:1)
    at main.9918d4723eeee42a175e.js:1
    at e (main.9918d4723eeee42a175e.js:1)
    at e.get (main.9918d4723eeee42a175e.js:1)
    at Ir (main.9918d4723eeee42a175e.js:1)
    at e.get (main.9918d4723eeee42a175e.js:1)
    at bi (main.9918d4723eeee42a175e.js:1)
main.9918d4723eeee42a175e.js:1 [WDS] Warnings while compiling.
warnings @ main.9918d4723eeee42a175e.js:1
main.9918d4723eeee42a175e.js:1 ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
132:230-248 "export 'FooterComponent' (imported as 'i1') was not found in '@canyaio/common-lib'
warnings @ main.9918d4723eeee42a175e.js:1
main.9918d4723eeee42a175e.js:1 ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
133:86-104 "export 'FooterComponent' (imported as 'i1') was not found in '@canyaio/common-lib'
warnings @ main.9918d4723eeee42a175e.js:1
main.9918d4723eeee42a175e.js:1 ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
17:1349-1369 "export 'HttpLoaderFactory' (imported as 'i1') was not found in '@canyaio/common-lib'
warnings @ main.9918d4723eeee42a175e.js:1
main.9918d4723eeee42a175e.js:1 ./src/app/missing-metamask/container.component.ngfactory.js
17:1812-1830 "export 'FooterComponent' (imported as 'i3') was not found in '@canyaio/common-lib'
warnings @ main.9918d4723eeee42a175e.js:1
main.9918d4723eeee42a175e.js:1 ./src/app/document-index/documents-index-wrapper/documents-index-wrapper.component.ngfactory.js
28:2029-2048 "export 'FooterComponent' (imported as 'i14') was not found in '@canyaio/common-lib'
warnings @ main.9918d4723eeee42a175e.js:1
main.9918d4723eeee42a175e.js:1 ./src/app/document-request-signatures/documents-request-signatures-wrapper/documents-request-signatures-wrapper.component.ngfactory.js
31:2021-2040 "export 'FooterComponent' (imported as 'i17') was not found in '@canyaio/common-lib'
warnings @ main.9918d4723eeee42a175e.js:1
main.9918d4723eeee42a175e.js:1 ./src/app/document-sign/documents-sign-wrapper/documents-sign-wrapper.component.ngfactory.js
32:1994-2013 "export 'FooterComponent' (imported as 'i18') was not found in '@canyaio/common-lib'
warnings @ main.9918d4723eeee42a175e.js:1
main.9918d4723eeee42a175e.js:1 ./src/app/app.module.ngfactory.js
46:3726-3747 "export 'HttpLoaderFactory' (imported as 'i15') was not found in '@canyaio/common-lib'
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jun 28, 2018

Can you try to remove the barrel files (aka export * from)

Unfortunitly there are a lot of issues when using barrel files and generating metadata.

Such as; angular/angular#23713 &
angular/angular#20931

And this might very well be one of those. Unfortunately I cannot test it right away my self.

@netpoe
Copy link
Author

netpoe commented Jun 28, 2018

@alan-agius4 thanks for the references.

I've checked my project library and updated the only barrels I found:

projects/common-lib/src/lib/public_api.ts
From:

export * from './lib/@model/language.model';
export * from './lib/@model/nav-item.model';
export * from './lib/@service/language.service';
export * from './lib/@pipe/keep-html.pipe';
export * from './lib/header/header.component';
export * from './lib/footer/footer.component';
export * from './lib/language-switch/language-switch.component';
export * from './lib/common-lib.module';

To:

export { Language } from './lib/@model/language.model';
export { NavItem } from './lib/@model/nav-item.model';
export { LanguageService } from './lib/@service/language.service';
export { KeepHtmlPipe } from './lib/@pipe/keep-html.pipe';
export { HeaderComponent } from './lib/header/header.component';
export { FooterComponent } from './lib/footer/footer.component';
export { LanguageSwitchComponent } from './lib/language-switch/language-switch.component';
export { CommonLibModule } from './lib/common-lib.module';

Packaged the library, published it, installed it and ng build --prod again with no luck. Still getting the same warnings:

Date: 2018-06-28T19:19:01.324Z
Hash: 652333127e9470909add
Time: 171043ms
chunk {0} runtime.a66f828dca56eeb90e02.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.3b401f7315e1889fc196.css (styles) 184 kB [initial] [rendered]
chunk {2} polyfills.16be5397c080c6bf4c93.js (polyfills) 59.8 kB [initial] [rendered]
chunk {3} main.4ed5696c28ad20f891b4.js (main) 4.23 MB [initial] [rendered]

WARNING in ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
132:230-248 "export 'FooterComponent' (imported as 'i1') was not found in '@canyaio/common-lib'

WARNING in ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
133:86-104 "export 'FooterComponent' (imported as 'i1') was not found in '@canyaio/common-lib'

WARNING in ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
17:1349-1354 "export 'ɵa' (imported as 'i1') was not found in '@canyaio/common-lib'

WARNING in ./src/app/missing-metamask/container.component.ngfactory.js
17:1812-1830 "export 'FooterComponent' (imported as 'i3') was not found in '@canyaio/common-lib'

WARNING in ./src/app/document-index/documents-index-wrapper/documents-index-wrapper.component.ngfactory.js
28:2029-2048 "export 'FooterComponent' (imported as 'i14') was not found in '@canyaio/common-lib'

WARNING in ./src/app/document-request-signatures/documents-request-signatures-wrapper/documents-request-signatures-wrapper.component.ngfactory.js
31:2021-2040 "export 'FooterComponent' (imported as 'i17') was not found in '@canyaio/common-lib'

WARNING in ./src/app/document-sign/documents-sign-wrapper/documents-sign-wrapper.component.ngfactory.js
32:1994-2013 "export 'FooterComponent' (imported as 'i18') was not found in '@canyaio/common-lib'

WARNING in ./src/app/app.module.ngfactory.js
46:3726-3732 "export 'ɵa' (imported as 'i15') was not found in '@canyaio/common-lib'

What's funny though, is that the packager did this in the canya-common-lib.d.ts:

/**
 * Generated bundle index. Do not edit.
 */
export * from './public_api';
export { HttpLoaderFactory as ɵa } from './lib/common-lib.module'; // <--- ɵa ?

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jun 29, 2018

The following is normal when building in AOT.

export { HttpLoaderFactory as ɵa } from './lib/common-lib.module'; // <--- ɵa ?

I tried to look into this, but the app provided has too has too many unrelated errors.

Can you setup a minimal reproduction please?

You can read here why this is needed. A good way to make a minimal reproduction is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

@netpoe
Copy link
Author

netpoe commented Jun 29, 2018

@alan-agius4 sure!

Actually, I made some progress using the library in a different Angular 6 app. You should be able to run both by cloning them, npm installing them and ng serving them.

In this app: https://github.com/canyaio/CANShare/blob/master/src/app/app.module.ts#L24
I'm importing the CommonLibModule from the packaged library and ng build --prod does not break.

One important thing to notice here is that the app consists of only 1 module, the app.module.ts

Now, take a look at this Angular 6 app, the one that has the warnings: https://github.com/canyaio/CANSign/tree/master/src/app

It's importing the same CommonLibModule, however this app has multiple modules apart from the app.module.ts.
I'm importing the CommonLibModule in each child module and I get the errors:

$ ng serve --prod                                                                                                                                                       
****************************************************************************************
This is a simple server for use in testing or debugging Angular applications locally.
It hasn't been reviewed for security issues.

DON'T USE IT FOR PRODUCTION!
****************************************************************************************
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

Date: 2018-06-29T15:49:30.410Z
Hash: 97241967f70921f3c220
Time: 212011ms
chunk {0} runtime.a66f828dca56eeb90e02.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.3b401f7315e1889fc196.css (styles) 184 kB [initial] [rendered]
chunk {2} polyfills.16be5397c080c6bf4c93.js (polyfills) 59.8 kB [initial] [rendered]
chunk {3} main.44e8a6f91ec47f6fc0bc.js (main) 4.36 MB [initial] [rendered]

WARNING in ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
132:230-248 "export 'FooterComponent' (imported as 'i1') was not found in '@canyaio/common-lib'

WARNING in ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
133:86-104 "export 'FooterComponent' (imported as 'i1') was not found in '@canyaio/common-lib'

WARNING in ./node_modules/@canyaio/common-lib/canyaio-common-lib.ngfactory.js
17:1349-1354 "export 'ɵa' (imported as 'i1') was not found in '@canyaio/common-lib'

WARNING in ./src/app/app.component.ngfactory.js
24:1751-1769 "export 'FooterComponent' (imported as 'i6') was not found in '@canyaio/common-lib'

WARNING in ./src/app/app.module.ngfactory.js
46:3726-3732 "export 'ɵa' (imported as 'i15') was not found in '@canyaio/common-lib'

Could it be something with child modules?

Am I exporting the library suitable for child modules? https://github.com/canyaio/Common/tree/master/projects/common-lib/src

@alan-agius4
Copy link
Collaborator

I tried to look at this and once again the git repository provided is full of unrelated errors.

Such as;

ng build --prod
The src/environments/environment.ts path in file replacements does not exist.

And If I fix that more errors pop-up.

Please provide a reproduction with the bare minimum needed to get the errors. A good way to start is using ng new repro-app

@netpoe
Copy link
Author

netpoe commented Jun 29, 2018

@alan-agius4 I made it work by rm -rf node_modules of the external app using the library and npm install back again, then ng build --prod

Suddenly worked without warnings and no errors.

Seemed like a cache issue.

Thanks for your help

@netpoe netpoe closed this as completed Jun 29, 2018
@laduguer
Copy link

laduguer commented Aug 4, 2018

Had the same issue with a own shared library, only appeared in one of our apps running that lib version.
@netpoe 's suggestion to clear node_modules and reinstall worked for me, for now.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants