angularangular-ui-router

module build failed in angular router


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


Solution

  • 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