【问题标题】:I am getting error while production build ng build --prod生产构建 ng build --prod 时出现错误
【发布时间】:2019-11-29 02:46:19
【问题描述】:

当生产构建项目在 Angular 4.4.4 上并且出现以下错误时,我收到以下错误。

在 5113:8 处缺少字体大小的警告。忽略。

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)

当我使用 ng build --env=prod 时,生成的不是 build 但 build 不是生产版本,但是当我按照角度文档使用命令时 ng build --prod 发生上述错误。 我正在使用 ubuntu 18。

【问题讨论】:

    标签: angular build angular-cli angular2-routing


    【解决方案1】:

    您收到的错误表明您有几个未在任何模块中声明的组件(在错误消息中命名)。

    如消息所示,您必须在模块中声明这些组件。

    非产品构建工作的原因是因为它实际上并没有编译所有内容 - 一些代码被解释,并且完成的检查并不完整。

    【讨论】:

      【解决方案2】:

      很难从这里调试,但你可以这样做:

      • 检查相关的@NgModule-s,是否有某种语法错误
      • 检查相关组件是否已添加到相应的@NgModule(同时检查导出和声明)
      • 删除整个 node_modules 文件夹,然后通过 npm install 重新安装它们
      • 检查 main.ts 以及所有引用的文件

      【讨论】:

        猜你喜欢
        • 2022-08-03
        • 1970-01-01
        • 1970-01-01
        • 2020-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-09
        • 1970-01-01
        相关资源
        最近更新 更多