我在生产构建 ng 构建 --prod 时遇到错误



当生产构建项目在 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时,会生成构建,但构建不是生产构建,但是当我根据角度文档使用该命令时ng build --prod发生上述错误。我正在使用 ubuntu 18。

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

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

非生产构建之所以有效,是因为它实际上并没有编译所有内容 - 一些代码被解释,并且完成的检查并不那么完整。

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

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

相关内容

最新更新