模块在Angular路由器中构建失败。

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

module build failed in angular router

问题

I'm here to provide the translated content as requested:

你好,我正在尝试创建一个Angular项目,在创建项目后,当我运行 ng s 时,出现以下错误。我已经删除了 node_modules 并重新安装,创建了一个新的文件夹并再次尝试,但仍然出现相同的错误。请帮助我。提前感谢。

./node_modules/@angular/router/fesm2022/router.mjs - 错误模块构建失败来自 ./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无法读取未定义的属性读取 '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"
  }
}

如果您需要更多帮助,请告诉我。

英文:

Hi I am trying to create a angular project, after creating the project when i gave ng s it is throwing the following error. I have deleted the node modules and re installed again, created a new folder and tried again, same error. Kindly help me out. Thanks in advance

./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"
  }
}

答案1

得分: 3

一个临时解决方案可能是:

  1. 删除 node_modules 文件夹
  2. 将以下行添加到您的 package.json 的依赖部分:
"@babel/generator": "7.22.5",
"@babel/parser": "7.22.5",
"@babel/traverse": "7.22.5",
  1. 运行 npm install
  2. 然后运行 ng serve
英文:

A temporary solution could be:

  1. Delete node_modules folder
  2. Add the following lines to your package.json's dependency section:
    "@babel/generator": "7.22.5",
	"@babel/parser": "7.22.5",
	"@babel/traverse": "7.22.5",
  1. Run npm install
  2. Then ng serve

答案2

得分: 0

昨天在擦除 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:
> 无法读取未定义的属性(读取 'file')
>
>
>
> ./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:
> 无法读取未定义的属性(读取 'file')
>
>
>
> ./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:
> 无法读取未定义的属性(读取 'file')
>
>
>
> ./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:
> 无法读取未定义的属性(读取 'file')
>
>
>
> ./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:
> 无法读取未定义的属性(读取 'file')
>
>
>
> ./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:
> 无法读取未定义的属性(读取 'file')
>
>
>
> ./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:
> 无法读取未定义的属性(读取 'file')
>
>
>
> ./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:
> 无法读取未定义的属性(读取 'file')
>
>
>
> ./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:
> 无法读取未定义的属性(读取 'file')
>
>
>
> ./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:
> 无法读取未定义的属性(读取 'file')

英文:

Yesterday worked fine (after erase package-lock.json and node_modules and run npm i) today I'm getting this problems after same procedure.

> ./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:
> /node_modules/@angular/common/fesm2022/common.mjs:
> Cannot read properties of undefined (reading 'file')
>
>
>
> ./node_modules/@angular/common/fesm2022/http.mjs - Error: Module build
> failed (from
> ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
>
> TypeError:
> /v1/node_modules/@angular/common/fesm2022/http.mjs:
> Cannot read properties of undefined (reading 'file')
>
>
>
> ./node_modules/@angular/forms/fesm2022/forms.mjs - Error: Module build
> failed (from
> ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
>
> TypeError:
> /v1/node_modules/@angular/forms/fesm2022/forms.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:
> /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:
> /v1/node_modules/@angular/router/fesm2022/router.mjs:
> Cannot read properties of undefined (reading 'file')
>
>
>
> ./node_modules/@ng-bootstrap/ng-bootstrap/fesm2022/ng-bootstrap.mjs -
> Error: Module build failed (from
> ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
>
> TypeError:
> /v1/node_modules/@ng-bootstrap/ng-bootstrap/fesm2022/ng-bootstrap.mjs:
> Cannot read properties of undefined (reading 'file')
>
>
>
> ./node_modules/@ng-select/ng-select/fesm2022/ng-select-ng-select.mjs -
> Error: Module build failed (from
> ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
>
> TypeError:
> /v1/node_modules/@ng-select/ng-select/fesm2022/ng-select-ng-select.mjs:
> Cannot read properties of undefined (reading 'file')
>
>
>
> ./node_modules/@ngx-translate/core/fesm2020/ngx-translate-core.mjs -
> Error: Module build failed (from
> ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
>
> TypeError:
> /v1/node_modules/@ngx-translate/core/fesm2020/ngx-translate-core.mjs:
> Cannot read properties of undefined (reading 'file')
>
>
>
> ./node_modules/angularx-qrcode/fesm2022/angularx-qrcode.mjs - Error:
> Module build failed (from
> ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
>
> TypeError:
> /v1/node_modules/angularx-qrcode/fesm2022/angularx-qrcode.mjs:
> Cannot read properties of undefined (reading 'file')
>
>
>
> ./node_modules/ngx-captcha/fesm2020/ngx-captcha.mjs - Error: Module
> build failed (from
> ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
>
> TypeError:
> /v1/node_modules/ngx-captcha/fesm2020/ngx-captcha.mjs:
> Cannot read properties of undefined (reading 'file')

答案3

得分: 0

不是实际答案,但我从今早开始就遇到了同样的问题,昨天还一切正常。npm clean cache --force或重新安装node_modules似乎无法解决它。

英文:

Not an actual answer, but I've the same issue since this morning, it was working fine yesterday. npm clean cache --force or reinstalling the node_modules doesn't seems to fix it.

答案4

得分: 0

这是一个来自Angular的全球性问题。链接:https://github.com/angular/angular/issues/50961

英文:

it's a global issue that's coming from angular. https://github.com/angular/angular/issues/50961

答案5

得分: 0

from the past 1 hour experiencing the same issue, did anyone find the solution to this?
TIA

Edit: Found Some Fix -

add this to package.json

"overrides": {
  "@babel/traverse": "7.22.6"
}

delete node_modules

npm install & ng serve

英文:

from the past 1 hour experiencing the same issue, did anyone find the solution to this?
TIA

Edit: Found Some Fix -

add this to package.json

"overrides": {
  "@babel/traverse": "7.22.6"
}

delete node_modules

npm install & ng serve

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

发表评论

匿名网友

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

确定