0
votes

I have tried with all given solutions like updating angular/cli and even uninstalling and reinstalling node/npm. I can create new project and it works as expected but when I am trying run ng serve command on my existing project it is showing me below error. Please help to resolve this.

module.js:549 throw error; ^
Error: Cannot find module './template' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object. (E:\Project\Nitesh\AngularMergedCode\AngularDemo\node_modules\@angular-devkit\core\src\utils\index.js:19:10) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) PS E:\Project\Nitesh\AngularMergedCode\AngularDemo> npm update PS E:\Project\Nitesh\AngularMergedCode\AngularDemo> ng serve

Package.json file :

{
  "name": "offica-replica",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.3",
    "@angular-devkit/build-angular": "^0.6.8",
    "@angular/animations": "^6.0.9",
    "@angular/common": "^6.0.9",
    "@angular/compiler": "^6.0.9",
    "@angular/core": "^6.0.9",
    "@angular/forms": "^6.0.9",
    "@angular/http": "^6.0.9",
    "@angular/platform-browser": "^6.0.9",
    "@angular/platform-browser-dynamic": "^6.0.9",
    "@angular/router": "^6.0.9",
    "core-js": "^2.5.4",
    "ngx-infinite-scroll": "^6.0.1",
    "ngx-pagination": "^3.1.1",
    "ngx-spinner": "^6.0.0",
    "ngx-toastr": "^8.9.1",
    "rxjs": "^6.2.2",
    "rxjs-compat": "^6.2.2",
    "template": "^0.17.5",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/cli": "^6.0.8",
    "@angular/compiler-cli": "^6.0.9",
    "@angular/language-service": "^6.0.9",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}
1
please share your package.json file.Syed Ali Taqi
I have shared the file. @SyedAliTaqiGarima Kinra
as you said, the error comes on existing project and new projects runs fine. Did you follow the correct path while migrating your old project to Angular 6? you can check the guide here.Syed Ali Taqi
have you try to run npm install @GarimaKinramalbarmavi
The project was running fine earlier but once the vscode editor got crash down after which the project stopped compiling.Though i m not sure whether this is the reason or not.So, I don't think migration could be the issue.Please suggest.@Syed Ali TaqiGarima Kinra

1 Answers

0
votes

I resolved this problem, It was a missing module problem so i need to perform these 2 steps:

1.Remove node_modules folder from project directory.

  1. Run command npm install (This will reinstall all missing modules)

    After this ng serve command works fine.