NG_PERSISTENT_BUILD_CACHE=1 ng serve not working

Solution 1:

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).