尝试构建 Angular 构建时收到错误

Posted

技术标签:

【中文标题】尝试构建 Angular 构建时收到错误【英文标题】:Receiving error while try to build Angular build 【发布时间】:2021-10-07 09:08:05 【问题描述】:

我正在尝试为Production 构建我的Angular Application

当我尝试时

ng build --prod

我收到此错误

Option "--prod" is deprecated: Use "--configuration production" instead.
Option "extractCss" is deprecated: Deprecated since version 11.0. No longer required to disable CSS extraction for HMR.
⠋ Generating browser application bundles (phase: setup)...An unhandled exception occurred: ENOENT: no such file or directory, lstat '/Users/xxx/Documents/GitHub/spa/node_modules/primeng/resources/themes/nova-light'
See "/private/var/folders/ft/644bz6_17vj4yr0q_j3wxzdm0000gn/T/ng-wiA0sW/angular-errors.log" for further details.

后来我试过了

ng build -- --prod

我收到了这个错误

Unknown option: '--prod'

所以我又试了一次

npm run build -- --prod

我收到了这个错误

Option "--prod" is deprecated: Use "--configuration production" instead.
Option "extractCss" is deprecated: Deprecated since version 11.0. No longer required to disable CSS extraction for HMR.
⠋ Generating browser application bundles (phase: setup)...An unhandled exception occurred: ENOENT: no such file or directory, lstat '/Users/xx/Documents/GitHub/spa/node_modules/primeng/resources/themes/nova-light'
See "/private/var/folders/ft/644bz6_17vj4yr0q_j3wxzdm0000gn/T/ng-0IJZJW/angular-errors.log" for further details.
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! app@0.0.0 build: `ng build --prod "--prod"`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the app@0.0.0 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!     /Users/xx/.npm/_logs/2021-08-01T21_01_45_518Z-debug.log

【问题讨论】:

你试过ng build --configuration production吗? 【参考方案1】:

我也偶然发现了这一点。如果你纯粹是使用 Angular,那么

ng build --configuration production

如果您的项目有像 Azure 静态 Web 应用这样的 ng + API 节点后端,那么

npm run build --configuration

注意:不要做npm run build --configuration production,它会导致

ng build --prod "production" 发生未处理的异常:项目 “生产”不存在。

【讨论】:

以上是关于尝试构建 Angular 构建时收到错误的主要内容,如果未能解决你的问题,请参考以下文章

使用Angular与TypeScript构建Electron应用

如何从 Visual Studio 2015 更新 3 中的构建中排除 node_module 文件夹

构建 Angular 项目导致内存不足

在 Linux 上使用 Angular4 构建 JHipster 时的问题

尝试在生产中构建 Angular 应用程序时出现数据表错误

没有 ngModule 的 ng 构建错误