angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open netpoe opened this issue 8 years ago • 27 comments

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.

netpoe avatar Jun 27 '18 23:06 netpoe

@andrewantar ... Can you please share the error, from what i experienced...one of the above should fix the issues... try the build with --verbose option to get the issue in more detail...

subodhkumar avatar Mar 19 '19 04:03 subodhkumar

I had the same issue with Angular 7. "ng build" was fine but "ng build --prod" failed on 2 files saying it couldn't find the imported @module, even though that same @module was imported on several other files just fine. It turned out removing unused interfaces pulled from the @module fixed the issue. It seems a mix of used and unused interfaces causes the import to fail (with a bad message about the whole file not being found) -- It didn't complain if all imported items were unused, precompiler probably just removed the entire reference. Also, this was a named @module that just exported Interfaces. Other "normal" unused references from other modules were ignored.

goresc avatar Apr 19 '19 19:04 goresc

I resolve this error by using the followed command, after building the library: npm install dist/libraryName --save "dist" is the directory of the library.

meysamsahragard avatar May 22 '19 10:05 meysamsahragard

help I have a problem problem mark me this error when I put the command ng build --prod

Date: 2019-06-26T19:47:29.429Z Hash: 47649eb13e262d7eaef3 Time: 45551ms chunk {0} runtime-es5.741402d1d47331ce975c.js (runtime) 1.41 kB [entry] [rendered] chunk {1} main-es5.7c04bb8524a34ea08589.js (main) 828 kB [initial] [rendered] chunk {2} polyfills-es5.b8d6dd293b73bbb8581d.js (polyfills) 132 kB [initial] [rendered] chunk {scripts} scripts.000eefc49a6f20ab379c.js (scripts) 607 kB [entry] [rendered]

ERROR in scripts.000eefc49a6f20ab379c.js from Terser Unexpected character '@' [scripts.000eefc49a6f20ab379c.js:17652,1]

JahyrLopez avatar Jun 26 '19 20:06 JahyrLopez

please help help

JahyrLopez avatar Jun 26 '19 22:06 JahyrLopez

help I have a problem problem mark me this error when I put the command ng build --prod

Date: 2019-06-26T19:47:29.429Z Hash: 47649eb13e262d7eaef3 Time: 45551ms chunk {0} runtime-es5.741402d1d47331ce975c.js (runtime) 1.41 kB [entry] [rendered] chunk {1} main-es5.7c04bb8524a34ea08589.js (main) 828 kB [initial] [rendered] chunk {2} polyfills-es5.b8d6dd293b73bbb8581d.js (polyfills) 132 kB [initial] [rendered] chunk {scripts} scripts.000eefc49a6f20ab379c.js (scripts) 607 kB [entry] [rendered]

ERROR in scripts.000eefc49a6f20ab379c.js from Terser Unexpected character '@' [scripts.000eefc49a6f20ab379c.js:17652,1]

I have same error please someone can help us ???

leparfait avatar Jul 30 '19 16:07 leparfait

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.