Skip to content

Angular 6 app with angular library: ng build works but ng build --prod throws "ERROR in ./src/app/app.component.ngfactory.js" #11392

@netpoe

Description

@netpoe

Bug Report or Feature Request (mark with an x)

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

Area

- [x] devkit
- [ ] schematics

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.ts

I run ng serve and ng build without errors. But when I run ng serve --prod or ng build --prod. The build fails after the 92% ... UglifyTask :

The log given by the failure

ERROR in ./dist/common-lib/canyaio-common-lib.ngfactory.js
Module not found: Error: Can't resolve '@canyaio/common-lib' in '/Users/GustavoIbarra/Projects/Angular/canya-common/dist/common-lib'
ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve '@canyaio/common-lib' in '/Users/GustavoIbarra/Projects/Angular/canya-common/src/app'
ERROR in ./src/app/app.component.ngfactory.js
Module not found: Error: Can't resolve '@canyaio/common-lib' in '/Users/GustavoIbarra/Projects/Angular/canya-common/src/app'

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 or ng build lets the app run without problems. ng serve --prod or ng build --prod fails.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions