Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NG_PERSISTENT_BUILD_CACHE=1 ng serve not working

I am trying to use the persistent build cache feature provided by angular but look like its not working for me, I am trying the below command

NG_PERSISTENT_BUILD_CACHE=1 ng serve

It always returns below error

'NG_PERSISTENT_BUILD_CACHE' is not recognized as an internal or external command,operable program or batch file.

I am using angular cli version 12.2.15. I am not sure what I am missing. Below is my packages.json file

"dependencies": {
    "@agm/core": "^1.1.0",
    "@angular-devkit/core": "^12.2.15",
    "@angular/animations": "^12.2.15",
    "@angular/common": "^12.2.15",
    "@angular/compiler": "^12.2.15",
    "@angular/core": "^12.2.15",
    "@angular/forms": "^12.2.15",
    "@angular/platform-browser": "^12.2.15",
    "@angular/platform-browser-dynamic": "^12.2.15",
    "@angular/platform-server": "^12.2.15",
    "@angular/pwa": "^0.1100.2",
    "@angular/router": "^12.2.15",
    "@angular/service-worker": "^12.2.15",
    "@auth0/angular-jwt": "5.0.2",
    "@ng-bootstrap/ng-bootstrap": "^8.0.0",
    "@nguniversal/module-map-ngfactory-loader": "^8.1.1",
    "@ngx-translate/core": "^13.0.0",
    "@ngx-translate/http-loader": "^6.0.0",
    "@types/ckeditor": "^4.9.10",
    "@types/hammerjs": "^2.0.36",
    "@types/jest": "^26.0.15",
    "@types/node": "^14.14.10",
    "@types/papaparse": "^5.3.1",
    "@webcomponents/shadydom": "^1.9.0",
    "acorn": "^8.0.4",
    "angular-chart.js": "^1.1.1",
    "angular-file-uploader": "7.0.3",
    "angular-mydatepicker": "^0.10.2",
    "angular-ng-autocomplete": "^2.0.1",
    "angular-split": "4.0.0",
    "angular2-datetimepicker": "^1.1.1",
    "angular2-text-mask": "9.0.0",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^4.5.3",
    "ckeditor": "4.12.1",
    "core-js": "^3.8.0",
    "events": "^3.2.0",
    "export-to-csv": "^0.2.1",
    "first": "0.0.3",
    "fullcalendar": "^4.0.0-alpha.4",
    "fullcalendar-scheduler": "^4.0.0-alpha.4",
    "hammerjs": "^2.0.8",
    "highcharts": "^8.2.2",
    "html2canvas": "^1.0.0-rc.7",
    "jquery": "^3.5.1",
    "jspdf": "^2.1.1",
    "jw-angular-social-buttons": "^1.0.0",
    "mdn-polyfills": "^5.20.0",
    "moment-mini-ts": "^2.20.1",
    "ng-multiselect-dropdown": "^0.2.10",
    "ng2-ckeditor": "^1.2.9",
    "ng2-date-picker": "11.0.0",
    "ng2-pdf-viewer": "6.2.0",
    "ng2-slim-loading-bar": "^4.0.0",
    "ng4-loading-spinner": "^1.2.3",
    "ng5-slider": "^1.2.6",
    "ng9-password-strength-bar": "^1.0.0",
    "ngx-bootstrap": "6.2.0",
    "ngx-color-picker": "^10.1.0",
    "ngx-countdown": "11.0.0",
    "ngx-device-detector": "^1.5.2",
    "ngx-drag-drop": "^2.0.0",
    "ngx-fullcalendar": "^5.0.0-alpha.1",
    "ngx-hm-sortable": "^1.0.0",
    "ngx-img-cropper": "^10.0.0",
    "ngx-infinite-scroll": "^10.0.0",
    "ngx-mask": "11.1.4",
    "ngx-mega-simple-drag-drop-list": "^1.0.8",
    "ngx-order-pipe": "^2.1.1",
    "ngx-papaparse": "^5.0.0",
    "ngx-print": "^1.2.0-beta.5",
    "ngx-select-dropdown": "^1.4.4",
    "ngx-sortable": "^1.0.3",
    "ngx-sortablejs": "^10.0.0",
    "ngx-toastr": "^13.1.0",
    "papaparse": "^5.3.0",
    "pdfjs-dist": "2.3.200",
    "rxjs": "^6.6.3",
    "rxjs-compat": "^6.6.3",
    "signature_pad": "^3.0.0-beta.4",
    "sortablejs": "^1.12.0",
    "ts-deferred": "^1.0.4",
    "tslib": "^2.2.0",
    "webpack-bundle-analyzer": "^4.1.0",
    "xlsx": "^0.17.4",
    "zone.js": "~0.11.4",
    "zxcvbn": "^4.4.2"
  },

here is a snapshot when I am checking my package version using ng v command

enter image description here

like image 323
Kashif Hanif Avatar asked Nov 04 '25 07:11

Kashif Hanif


1 Answers

You seem to be using Windows cmd to run the command, and hence you are getting the error.

The command:

NG_PERSISTENT_BUILD_CACHE=1 ng serve

is for Unix-like systems and won't work within Windows cmd.


You can use any of the below methods to make it work:

  • First set environment variable and then run the command
// 1st command to set the environment variable
set NG_PERSISTENT_BUILD_CACHE=1

// 2nd command
ng serve
  • Run both commands within single step
set NG_PERSISTENT_BUILD_CACHE=1&&ng serve
  • Add the below command within package.json scripts and then run npm start
"scripts": {
  "start": "set NG_PERSISTENT_BUILD_CACHE=1&&ng serve",
  ...
}

PS: In all the above methods the environment variable value is set for the cmd session in which we run the command. If you want to set the environment variable globally, then that can be achieved by adding System variables within Environment Variables dialog. (System Properties -> Environment Variables -> System variables).

like image 124
Siddhant Avatar answered Nov 05 '25 21:11

Siddhant