How can I fix localStorage error in sapper/svelte
问题 import { writable } from 'svelte/store'; /** Read the current token from LocalStorage on boot */ const token = writable(localStorage.getItem('token')); /** Store the token in LocalStorage whenever it´s updated */ token.subscribe((val) => { if (!localStorage) return; if (!val) { return localStorage.removeItem('token'); } localStorage.setItem('token', val); }); export default token; I still get an error that localStorage is undefined in sapper when I run npm run dev 回答1: In Sapper, your code