Daniel Ocampo
Daniel Ocampo

Reputation: 256

LocalStorage is cleared after running yarn build

I have a React app and I am saving some simple data to LocalStorage. All works well across refreshes, etc. But when I run yarn build to refresh the built web after pushing a change, this will clear somehow the local storage.

I have a server setup with nginx and a reverse proxy, my web app being served through pm2.

Is this something expected to happen? Why does it happen and can it be avoided?

Thanks!

Upvotes: 0

Views: 434

Answers (2)

Daniel Ocampo
Daniel Ocampo

Reputation: 256

Thanks to @Aslam_khan reply I found the solution:

Use npm run build instead of yarn build if you want to prevent LocalStorage to be cleared up on every new build.

Upvotes: 0

Aslam khan
Aslam khan

Reputation: 343

Actually when you use yarn to run your code on browser it basically create a fresh session on browser on every refresh. therefore you loosing your data.

Upvotes: 1

Related Questions