Angular. ng serve. Module build failed. Cannot read properties of undefined (reading 'file')

huangapple go评论53阅读模式
英文:

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 中覆盖此依赖项:

&quot;overrides&quot;: {
    &quot;@babel/traverse&quot;: &quot;7.22.6&quot;
},

</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 :

&quot;overrides&quot;: {
    &quot;@babel/traverse&quot;: &quot;7.22.6&quot;
},

</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 !

huangapple
  • 本文由 发表于 2023年7月6日 20:07:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76628660.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定