构建 - 投掷错误

问题描述 投票:0回答:2

我正在使用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
angular build angular2-routing angular-cli
2个回答
0
投票

似乎是行节点缓存模块问题。请尝试以下命令:

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

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


0
投票

你可以验证的东西很少,

  1. 检查是否从正确的目录加载组件,我的意思是Import语句中组件的路径 import PackageName from './FromFolder';
  2. 删除node_modules并重新安装所有软件包
  3. 使用更新的软件包更新Angular CLI版本

现在试试ng build --prod

© www.soinside.com 2019 - 2024. All rights reserved.