Home > front end >  AngularJs CLI An unhandled exception occurred:catch clause variable is not an Error instance, while
AngularJs CLI An unhandled exception occurred:catch clause variable is not an Error instance, while

Time:07-26

Getting below error while creating component using ng g c my-component

'An unhandled exception occurred: catch clause variable is not an Error instance See "path-to-file\angular-errors.log" for further details.'

And file contains below stack trace: [error] AssertionError [ERR_ASSERTION]: catch clause variable is not an Error instance at assertIsError (C:\Users\sam\node_modules@angular\cli\src\utilities\error.js:16:26) at GenerateCommandModule.runSchematic (C:\Users\sam\node_modules@angular\cli\src\command-builder\schematics-command-module.js:311:43) at async GenerateCommandModule.handler (C:\Users\sam\node_modules@angular\cli\src\command-builder\command-module.js:109:24)

No luck even after updating angular cli

npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
npm cache verify
npm install -g @angular/cli@latest

below is my package.json file:

{
  "name": "my-sample-frontend",
  "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.1.0",
    "@angular/common": "^14.1.0",
    "@angular/compiler": "^14.1.0",
    "@angular/core": "^14.1.0",
    "@angular/forms": "^14.1.0",
    "@angular/platform-browser": "^14.1.0",
    "@angular/platform-browser-dynamic": "^14.1.0",
    "@angular/router": "^14.1.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.1.0",
    "@angular/cli": "~14.1.0",
    "@angular/compiler-cli": "^14.1.0",
    "@types/jasmine": "~4.0.0",
    "jasmine-core": "~4.2.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"
  }
}

CodePudding user response:

i tried your command its working for me . please check your path where u fire this command (ng g c my-component)

https://i.stack.imgur.com/d71m1.png

CodePudding user response:

I had the same issue.

I found that if the file is named with dots it gives error, for example: src/app/application.material.module.ts or src/app/application-material.module.ts

If you change the name to src/app/application-material-module.ts it works.

Regards!

  • Related