Node.js 20.6.0环境下Angular Demo执行ng serve报错的问题及解决
Angular
ng serve 报错:TypeError: Cannot redefine property: File 解决方案 搭建Angular测试演示环境时,执行ng serve命令出现如下错误:
- Generating browser application bundles (phase: building)...node:internal/process/promises:289 triggerUncaughtException(err, true /* fromPromise */); ^ TypeError: Cannot redefine property: File at Function.defineProperty (<anonymous>) at Object.<anonymous> (C:\Users\Carlo\Projects\test1\node_modules\@angular\compiler-cli\node_modules\@babel\core\lib\index.js:7:8) at Module._compile (node:internal/modules/cjs/loader:1241:14) at Module._extensions..js (node:internal/modules/cjs/loader:1295:10) at Module.load (node:internal/modules/cjs/loader:1091:32) at Module._load (node:internal/modules/cjs/loader:938:12) at Module.require (node:internal/modules/cjs/loader:1115:19) at require (node:internal/modules/helpers:130:18) at Object.<anonymous> (C:\Users\Carlo\Projects\test1\node_modules\@angular\compiler-cli\node_modules\@babel\core\lib\config\helpers\config-api.js:16:9) at Module._compile (node:internal/modules/cjs/loader:1241:14) Node.js v20.6.0
解决方案
- 切换Node.js版本至18.7.1,问题即可解决
- 测试前建议清理构建缓存,可执行命令:
ng cache clean(适用于Angular CLI 6+版本),或手动删除项目目录下的node_modules/.cache文件夹
内容的提问来源于stack exchange,提问作者Jose Carlos Rueda Garcia
相关产品推荐
相关产品推荐

