【问题标题】:ng build --prod throwing errrng build --prod 抛出错误
【发布时间】:2017-12-18 06:03:52
【问题描述】:

我正在使用ng build --prod 命令,但它显示错误

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './app/app.module.ngfactory' in 'C:\Users\allud\MyCafe\src'
resolve './app/app.module.ngfactory' in 'C:\Users\allud\MyCafe\src'
  using description file: C:\Users\allud\MyCafe\package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: C:\Users\allud\MyCafe\package.json (relative path: ./src)
    using description file: C:\Users\allud\MyCafe\package.json (relative path: ./src/app/app.module.ngfactory)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\allud\MyCafe\src\app\app.module.ngfactory doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\allud\MyCafe\src\app\app.module.ngfactory.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\allud\MyCafe\src\app\app.module.ngfactory.js doesn't exist
      as directory
        C:\Users\allud\MyCafe\src\app\app.module.ngfactory doesn't exist
[C:\Users\allud\MyCafe\src\app\app.module.ngfactory]
[C:\Users\allud\MyCafe\src\app\app.module.ngfactory.ts]
[C:\Users\allud\MyCafe\src\app\app.module.ngfactory.js]
[C:\Users\allud\MyCafe\src\app\app.module.ngfactory]
 @ ./src/main.ts 3:0-66
 @ multi ./src/main.ts

【问题讨论】:

  • 你也可以发布你的代码吗??
  • 我还没有编写任何代码。我刚刚开始使用 ng new myCafe、cd myCafe,然后是 ng build --prod。这是抛出错误。 ng serve 正常工作,所以代码还没有问题。
  • anglular 和 CLI 的哪个版本?
  • 角 cli 版本 1.6.0

标签: angular build angular2-routing angular-cli


【解决方案1】:

似乎线路节点缓存模块问题。 请尝试以下给定的命令:

cd {your-project}
npm -f cache clean 
rm -f package-lock.json
rm -rf node_modules
npm install

如果它不起作用,请清理主目录中的 .npm 和 .node-gyp。

【讨论】:

    【解决方案2】:

    您可以验证的事情很少,

    1. 检查你是否从正确的目录加载组件,我是指Import语句中的组件路径

      import PackageName from './FromFolder';
      
    2. 删除 node_modules 并重新安装所有包

    3. 使用更新的包更新您的 Angular CLI 版本

    现在试试ng build --prod

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 2022-09-25
      • 1970-01-01
      • 2020-10-02
      相关资源
      最近更新 更多