Cannot read property 'write' of undefined - Angular

1.2k Views Asked by At

I am working on an Angular 5 project where I'm facing issue Cannot read property 'write' of undefined while trying to build and run(ng serve): enter image description here

My local @angular/cli version is 1.7.4 and below are the versions of global @angular/cli, nodejs and npm:

Angular CLI: 14.2.1
Node: 14.17.3
Package Manager: npm 6.14.17
OS: win32 x64

Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1402.1 (cli-only)
@angular-devkit/core         14.2.1 (cli-only)
@angular-devkit/schematics   14.2.1 (cli-only)
@schematics/angular          14.2.1 (cli-only)

Below is my package.json file:

{
  "name": "my-app",
  "version": "0.0.0",
  "license": "Test",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod --build-optimizer=false",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/cdk": "^9.1.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@microsoft/microsoft-graph-client": "^1.0.0",
    "@microsoft/microsoft-graph-types": "^1.2.0",
    "@progress/kendo-theme-default": "^2.47.0",
    "@tinymce/tinymce-angular": "^2.0.0",
    "@types/jspdf": "^1.1.31",
    "adal-angular": "^1.0.17",
    "adal-angular-ts": "^1.1.6",
    "adal-angular5": "^1.0.36",
    "angular-2-local-storage": "^1.0.1",
    "angular-checklist": "^1.2.3",
    "angular-d3-charts": "^5.0.0",
    "angular-localstorage": "^1.1.5",
    "angular-sortablejs": "^2.6.0",
    "angular2-multiselect-dropdown": "^2.3.0",
    "angular2-tinymce": "^2.1.2",
    "angular2-toaster": "^4.0.1",
    "angular4": "^1.0.0",
    "chart.js": "^2.7.2",
    "core-js": "^2.4.1",
    "css-loader": "^0.28.8",
    "es6-promise": "^4.2.5",
    "expose-loader": "^0.7.5",
    "file-saver": "^1.3.8",
    "font-awesome": "^4.7.0",
    "hellojs": "^1.16.1",
    "html2pdf": "0.0.11",
    "html2pdf.js": "^0.9.1",
    "jspdf": "^1.5.3",
    "jspdf-autotable": "^2.3.2",
    "loader": "^2.1.1",
    "moment": "^2.22.1",
    "ng-multiselect-dropdown": "^0.1.2",
    "ng2-bootstrap-modal": "https://github.com/Sky4CE/ng2-bootstrap-modal/tarball/v.1.0.2",
    "ng2-drag-drop": "^3.0.2",
    "ng2-toastr": "^4.1.2",
    "ng2-trim-directive": "^2.1.7",
    "ng2cli": "^3.0.0",
    "ngx-charts": "^3.0.2",
    "ngx-device-detector": "^1.4.0",
    "ngx-tabs": "0.0.13",
    "ngx-toastr": "^8.4.0",
    "node-sass": "^4.13.1",
    "pdfmake": "^0.1.36",
    "powerbi-client": "^2.6.5",
    "primeicons": "^1.0.0-beta.10",
    "primeng": "^6.1.7",
    "quill": "^1.3.5",
    "request-options": "^2.0.0",
    "rxjs": "^5.5.2",
    "sortablejs": "^1.8.1",
    "toastr": "^2.1.4",
    "toggle": "^1.0.1",
    "upgrade-angular": "^0.1.3",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.7.1",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/adal": "^1.0.29",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "@types/quill": "^1.3.7",
    "@types/tinymce": "^4.5.16",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "jwt-decode": "^2.2.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

Note that a similar issue was raised earlier also Angular CLI error Cannot read property 'write' of undefined but this fix only applies to a specific version which I unfortunately can't use.

I've tried uninstalling @angular/cli globally, running command npm cache clean --force to clean the npm cache(although the command showed me only a warning npm WARN using --force I sure hope you know what you are doing. and no output as such) and then again installing the latest version of @angular/cli globally(npm install -g @angular/cli@latest), deleting node modules folder and re-installing them(npm install) but nothing worked.

I would highly appreciate any help whatsoever about this, thanks.

1

There are 1 best solutions below

0
Naren Murali On

Issue is due to version differences between global and local versions of @angular/cli Please sync up the versions, else you can run the below command

npx run start

above line will run only the local version of angular cli which run without any errors!