node.js - 尝试构建 Angular 构建时收到错误
问题描述
我正在尝试构建我Angular Application
的 for Production
。
当我尝试
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
解决方案
我也偶然发现了这一点。如果你纯粹是在 Angular 上,那么
ng build --configuration production
如果您的项目具有像 Azure 静态 Web 应用程序这样的 ng + API 节点后端,那么
npm run build --configuration
注意:不要这样做npm run build --configuration production
,它会导致
ng build --prod "production" 发生未处理的异常:项目 'production' 不存在。
推荐阅读
- python - 无法安装 auto-py-to-exe;找不到版本
- javascript - 修改并返回异步函数内的对象
- sql-server - 表值构造函数性能
- octave - 结果与预期相同,但在使用 Octave 的hackerrank 网站上使用不同的格式
- python - 将文件中的 TTree 复制到带有根目录的新文件中
- c# - 如何以格式(DD/MM 或 MM/DD)获取 DateTime,但考虑到文化
- c# - 此 EF 查询中有多少个数据库调用?
- reactjs - 为什么我不能更改 React 中的输入字段值?
- r - 从R中的变量中过滤掉数据点
- windows-subsystem-for-linux - WSL - explorer.exe 启动 System32 目录