英文:
Angular. ng serve. Module build failed. Cannot read properties of undefined (reading 'file')
问题
以下是您运行"ng serve"时遇到的错误:
./node_modules/@angular/common/fesm2022/common.mjs - 错误:模块构建失败(来自./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError:C:\ Users \ sheil \ Desktop \ Temp \ angular-tut \ node_modules \ @angular \ common \ fesm2022 \ common.mjs:无法读取未定义的属性(读取'file')
./node_modules/@angular/platform-browser/fesm2022/platform-browser.mjs - 错误:模块构建失败(来自./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError:C:\ Users \ sheil \ Desktop \ Temp \ angular-tut \ node_modules \ @angular \ platform-browser \ fesm2022 \ platform-browser.mjs:无法读取未定义的属性(读取'file')
./node_modules/@angular/router/fesm2022/router.mjs - 错误:模块构建失败(来自./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError:C:\ Users \ sheil \ Desktop \ Temp \ angular-tut \ node_modules \ @angular \ router \ fesm2022 \ router.mjs:无法读取未定义的属性(读取'file')
Angular Live Development Server正在侦听localhost:4200,打开您的浏览器并访问http://localhost:4200/。
× 编译失败。
我的package.json:
{
"name": "angular-tut",
"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": "^16.1.0",
"@angular/common": "^16.1.0",
"@angular/compiler": "^16.1.0",
"@angular/core": "^16.1.0",
"@angular/forms": "^16.1.0",
"@angular/platform-browser": "^16.1.0",
"@angular/platform-browser-dynamic": "^16.1.0",
"@angular/router": "^16.1.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
},
"devDependencies":{
"@angular-devkit/build-angular": "^16.1.3",
"@angular/cli": "~16.1.3",
"@angular/compiler-cli": "^16.1.0",
"@types/jasmine": "~4.3.0",
"jasmine-core": "~4.6.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.1.3"
}
}
英文:
I have the following error when running "ng serve":
./node_modules/@angular/common/fesm2022/common.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError: C:\Users\sheil\Desktop\Temp\angular-tut\node_modules@angular\common\fesm2022\common.mjs: Cannot read properties of undefined (reading 'file')
./node_modules/@angular/platform-browser/fesm2022/platform-browser.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
TypeError: C:\Users\sheil\Desktop\Temp\angular-tut\node_modules@angular\platform-browser\fesm2022\platform-browser.mjs: Cannot read properties of undefined (reading 'file')
./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: C:\Users\sheil\Desktop\Temp\angular-tut\node_modules@angular\router\fesm2022\router.mjs: Cannot read properties of undefined (reading 'file')
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
× Failed to compile.
My package.json:
{
"name": "angular-tut",
"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": "^16.1.0",
"@angular/common": "^16.1.0",
"@angular/compiler": "^16.1.0",
"@angular/core": "^16.1.0",
"@angular/forms": "^16.1.0",
"@angular/platform-browser": "^16.1.0",
"@angular/platform-browser-dynamic": "^16.1.0",
"@angular/router": "^16.1.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.1.3",
"@angular/cli": "~16.1.3",
"@angular/compiler-cli": "^16.1.0",
"@types/jasmine": "~4.3.0",
"jasmine-core": "~4.6.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.1.3"
}
}
答案1
得分: 4
这是您提供的内容的中文翻译:
这是与 @babel/traverse
相关的已知问题。
<del>
临时解决方法是在 package.json
中覆盖此依赖项:
"overrides": {
"@babel/traverse": "7.22.6"
},
</del>
<del>
Babel团队正在进行修复工作,可以在此处跟踪该问题。</del>
编辑:
babel
7.22.8
已发布。删除您的 package-lock
文件并进行干净安装!
英文:
It's known issue related to @babel/traverse
.
<del>
The temporary workaround is to override the dependency in package.json
:
"overrides": {
"@babel/traverse": "7.22.6"
},
</del>
<del>
A fix is being worked on by the babel team, the issue can be tracked here. </del>
Edit:
babel
7.22.8
has been published. Delete your package-lock
and do a clean install !
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论