ng-matero / ng-matero

Angular Material admin dashboard template.
https://ng-matero.github.io/ng-matero/
MIT License
1.2k stars 331 forks source link

`ng build` ERROR: localStorage is not defined #666

Open jeffmccune opened 2 months ago

jeffmccune commented 2 months ago

FYI, getting this error with a new project.

❯ ng build
⠴ Building...
ERROR ReferenceError: localStorage is not defined
❯ rg localStorage
src/app/shared/services/storage.service.ts
8:    return JSON.parse(localStorage.getItem(key) || '{}') || {};
12:    localStorage.setItem(key, JSON.stringify(value));
18:    return !!localStorage.getItem(key);
22:    localStorage.removeItem(key);
26:    localStorage.clear();
Angular Version ``` _ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | | / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | | /_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___| |___/ Angular CLI: 17.3.3 Node: 20.11.0 Package Manager: npm 10.2.4 OS: linux x64 Angular: 17.3.3 ... animations, cli, common, compiler, compiler-cli, core, forms ... platform-browser, platform-browser-dynamic, platform-server ... router, ssr Package Version ------------------------------------------------------------ @angular-devkit/architect 0.1703.3 @angular-devkit/build-angular 17.3.3 @angular-devkit/core 17.3.3 @angular-devkit/schematics 17.3.3 @angular/cdk 17.3.4 @angular/material 17.3.4 @angular/material-moment-adapter 17.3.4 @schematics/angular 17.3.3 rxjs 7.8.1 typescript 5.2.2 zone.js 0.14.4 ```
nzbin commented 2 months ago

Do you use SSR? The localStorage doesn't suppport SSR, so you can remove it by yourself.