欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

npm run build打包失败

程序员文章站 2022-05-30 09:45:57
...

使用npm run build命令打包Angular项目时报错,错误信息如下:

WARNING in budgets, maximum exceeded for initial. Budget 2 MB was exceeded by 3.33 MB.

ERROR in budgets, maximum exceeded for initial. Budget 5 MB was exceeded by 340 kB.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `npm run color-less && node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod --build-optimizer`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\zhang\AppData\Roaming\npm-cache\_logs\2020-05-09T02_27_47_586Z-debug.log

解决方法:
angular.json文件中找到budgets数组字段,扩大maximumWarningmaximumError属性值。

"budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "6mb",
                  "maximumError": "6mb"
                }
              ]

说明:
当应用的功能不断增长时,其文件大小也会同步增长。 CLI 允许你通过配置项来限制文件大小,以确保应用的各个部分都处于你定义的大小范围内。

你可以在 CLI 配置文件 angular.json 的 budgets 区段为每个所配置的环境定义这些大小范围。

{
  ...
  "configurations": {
    "production": {
      ...
      budgets: []
    }
  }
}

—— END ——