Solvedangular cli Angular 6 app with angular library: ng build works but ng build --prod throws "ERROR in ./src/app/app.component.ngfactory.js"
✔️Accepted Answer
Can you check if this has the same effect
npm run ng build -- --prod
Other Answers:
Thanks @daniel-nagy
I encountered this issue and got it resolved by adding another path in tsconfig.json.
ngfactory is looking for the name defined in library's package.json. It could be different from the original name used to create the library using angular cli.
matching the path like below resolved the issue (@my-repo/my-lib is the package name defined in library package.json).
"paths": {
"my-lib": [
"dist/my-lib"
],
"@my-repo/my-lib": [
"dist/my-lib"
],
"my-lib/*": [
"dist/my-lib/*"
]
}
Incase someone else lands here, I had the same issue but my problem was I prefixed the path with an @
in my tsconfig.json file. Development builds worked find but when building for production I got the following error:
ERROR in ./dist/my-library/my-library.ngfactory.js
Module not found: Error: Can't resolve 'my-library' in '/path/to/MyWorkSpace/dist/my-library'
ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve 'my-library' in '/path/to/MyWorkSpace/src/app'
As you can see, the generated factory classes are looking for my-library, not @my-library. I just removed the @
from my path mappings and it built fine.
Bug Report or Feature Request (mark with an
x
)Area
Versions
node v8.10.0
npm 6.1.0
macOS High Sierra
"@angular/core": "^6.0.3",
"@angular/cli": "~6.0.8",
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.tsI run
ng serve
andng build
without errors. But when I runng serve --prod
orng build --prod
. The build fails after the92% ... UglifyTask
:The log given by the failure
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
If I import the packaged library in an external Angular 6 application, the same happens:
ng serve
orng build
lets the app run without problems.ng serve --prod
orng build --prod
fails.