嗨,我正在尝试创建一个有角度的项目,在创建项目后,当我给出 ng s 时,它抛出以下错误。我已删除节点模块并再次重新安装,创建一个新文件夹并再次尝试,同样的错误。请帮助我。预先感谢
./node_modules/@angular/router/fesm2022/router.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError: E:\Downloads\SpringBootProjects\AngularNgPrime\client\node_modules\@angular\router\fesm2022\router.mjs: Cannot read properties of undefined (reading 'file')
package.json
{
"name": "client",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^14.2.0",
"@angular/common": "^14.2.0",
"@angular/compiler": "^14.2.0",
"@angular/core": "^14.2.0",
"@angular/forms": "^14.2.0",
"@angular/platform-browser": "^14.2.0",
"@angular/platform-browser-dynamic": "^14.2.0",
"@angular/router": "^14.2.0",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^14.2.12",
"@angular/cli": "~14.2.12",
"@angular/compiler-cli": "^14.2.0",
"@types/jasmine": "~4.0.0",
"jasmine-core": "~4.3.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~4.7.2"
}
}
临时解决方案可能是:
"@babel/generator": "7.22.5",
"@babel/parser": "7.22.5",
"@babel/traverse": "7.22.5",
npm install
ng serve
这是一个来自角度的全球性问题。 https://github.com/angular/angular/issues/50961
将此添加到 package.json
"overrides": {
"@babel/traverse": "7.22.6"
}
删除node_modules
npm install
& ng serve
不是一个实际的答案,但从今天早上开始我就遇到了同样的问题,昨天工作正常。
npm clean cache --force
或重新安装 node_modules
似乎无法解决问题。
昨天工作正常(在删除 package-lock.json 和 node_modules 并运行 npm i 之后)今天我在相同的过程后遇到了这个问题。
./node_modules/@angular/common/fesm2022/common.mjs - 错误:模块 构建失败(来自 ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /node_modules/@angular/common/fesm2022/common.mjs: 无法读取未定义的属性(读取“文件”)
./node_modules/@angular/common/fesm2022/http.mjs - 错误:模块构建 失败(来自 ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /v1/node_modules/@angular/common/fesm2022/http.mjs: 无法读取未定义的属性(读取“文件”)
./node_modules/@angular/forms/fesm2022/forms.mjs - 错误:模块构建 失败(来自 ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /v1/node_modules/@angular/forms/fesm2022/forms.mjs: 无法读取未定义的属性(读取“文件”)
./node_modules/@angular/platform-browser/fesm2022/platform-browser.mjs
- 错误:模块构建失败(来自./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /node_modules/@angular/platform-browser/fesm2022/platform-browser.mjs: 无法读取未定义的属性(读取“文件”)
./node_modules/@angular/router/fesm2022/router.mjs - 错误:模块 构建失败(来自 ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /v1/node_modules/@angular/router/fesm2022/router.mjs: 无法读取未定义的属性(读取“文件”)
./node_modules/@ng-bootstrap/ng-bootstrap/fesm2022/ng-bootstrap.mjs - 错误:模块构建失败(来自 ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /v1/node_modules/@ng-bootstrap/ng-bootstrap/fesm2022/ng-bootstrap.mjs: 无法读取未定义的属性(读取“文件”)
./node_modules/@ng-select/ng-select/fesm2022/ng-select-ng-select.mjs - 错误:模块构建失败(来自 ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /v1/node_modules/@ng-select/ng-select/fesm2022/ng-select-ng-select.mjs: 无法读取未定义的属性(读取“文件”)
./node_modules/@ngx-translate/core/fesm2020/ngx-translate-core.mjs - 错误:模块构建失败(来自 ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /v1/node_modules/@ngx-translate/core/fesm2020/ngx-translate-core.mjs: 无法读取未定义的属性(读取“文件”)
./node_modules/angularx-qrcode/fesm2022/angularx-qrcode.mjs - 错误: 模块构建失败(来自 ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /v1/node_modules/angularx-qrcode/fesm2022/angularx-qrcode.mjs: 无法读取未定义的属性(读取“文件”)
./node_modules/ngx-captcha/fesm2020/ngx-captcha.mjs - 错误:模块 构建失败(来自 ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
类型错误: /v1/node_modules/ngx-captcha/fesm2020/ngx-captcha.mjs: 无法读取未定义的属性(读取“文件”)