Search code examples
angularbuildangular-cliangular2-routing

I am getting error while production build ng build --prod


I am getting the following error while production build project is on angular 4.4.4 and error is following.

WARNING in Missing font size at 5113:8. Ignoring.

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/mnt/.local/share/Trash/files/front_end/src'
ERROR in Error: Cannot determine the module for class AddWebsiteAndCampaign in /home/mnt/.local/share/Trash/files/front_end/src/app/campaign/campaign-main/campaign-main.component.ts! Add AddWebsiteAndCampaign to the NgModule to fix it.
Cannot determine the module for class CompanyEditComponent in /home/mnt/.local/share/Trash/files/front_end/src/app/company/company-edit/company-edit.component.ts! Add CompanyEditComponent to the NgModule to fix it.
    at syntaxError (/home/mnt/.local/share/Trash/files/front_end/node_modules/@angular/compiler/bundles/compiler.umd.js:1729:34)
    at analyzeAndValidateNgModules (/home/mnt/.local/share/Trash/files/front_end/node_modules/@angular/compiler/bundles/compiler.umd.js:24306:15)
    at AotCompiler.analyzeModulesAsync (/home/mnt/.local/share/Trash/files/front_end/node_modules/@angular/compiler/bundles/compiler.umd.js:23937:46)
    at CodeGenerator.codegen (/home/mnt/.local/share/Trash/files/front_end/node_modules/@angular/compiler-cli/src/codegen.js:32:14)
    at Function.NgTools_InternalApi_NG_2.codeGen (/home/mnt/.local/share/Trash/files/front_end/node_modules/@angular/compiler-cli/src/ngtools_api.js:73:30)
    at _donePromise.Promise.resolve.then (/home/mnt/.local/share/Trash/files/front_end/node_modules/@ngtools/webpack/src/plugin.js:428:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:832:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

When I am use ng build --env=prod than build is generated but build is not a production build but when I use the command as per angular documentation ng build --prod above error happening. I am using ubuntu 18.


Solution

  • The error that you are getting indicates that you have a couple of components (named in the error message) that are not declared in any module.

    As the message indicates, you must declare these components in a module.

    The reason that a non-prod build works is because it doesn't actually compile everything - some of the code is interpreted instead, and the checking that is done is not as complete.