azu / localstorage-ponyfill

Universal LocalStorage for browser and Node.js.
MIT License
56 stars 0 forks source link

TypeError: Path must be a string. Received undefined #2

Open asparkam opened 7 years ago

asparkam commented 7 years ago

When i try to use localstorage in my isomorphic app:

const localStoraged = createLocalStorage();
localStorage.setItem("key", "12321321");

In sever console is:


path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.dirname (path.js:695:5)
    at resolve (path\to\project\server.js:65280:22)
    at module.exports.module.exports (path\to\project\server.js:6
5187:20)
    at Object.<anonymous> (path\to\project\server.js:65174:18)
    at Object.<anonymous> (path\to\project\server.js:65175:30)
    at __webpack_require__ (path\to\project\server.js:21:30)
    at createLocalStorage (path\to\project\server.js:65147:23)
    at Object.<anonymous> (path\to\project\server.js:6184:102)
    at __webpack_require__ (path\to\project\server.js:21:30)

Searching for this issue shows widespread problems with different libraries where path strings are being asserted instead of returning empty string if null. Suggestions were to downgrade to Node 5 or 4 from 6 (I do not wish to so this).

NPM version: 3.10.8 Node version: v6.9.1 Node architecture: x64 OS: Windows 7

azu commented 7 years ago

Thanks for report. Probably, It seem that app-root-path return undefined. This is a bug. I will look into it.

https://github.com/azu/localstorage-ponyfill/blob/8fb4476652bfdf366031fc247d2ad37cc14f7120/src/localstorage-ponyfill.ts#L43 ( node-localstorage rquire store path )

You can avoid this issue by storeFilePath options.

const localStoraged = createLocalStorage({ 
     storeFilePath: __dirname + "/local-storage"
});
localStorage.setItem("key", "12321321");