creately / rxdata

A reactive document database for web browsers
MIT License
11 stars 1 forks source link

ReferenceError: localStorage is not defined #44

Closed 4F2E4A2E closed 5 years ago

4F2E4A2E commented 6 years ago

Using @creately/rxdata:4.3.5 as described in it's readme

import { Database } from 'rxdata'

const db = new Database('test-db')
const vehicles = db.collection('vehicles')

delivers following error:

ReferenceError: localStorage is not defined
    at Database.get [as collectionsList] (...\node_modules\@creately\rxdata\src\database.ts:55:17)
    at Database.registerCollection (...\node_modules\@creately\rxdata\src\database.ts:71:23)
    at Database.createCollection (...\node_modules\@creately\rxdata\src\database.ts:81:10)
    at Database.collection (...\node_modules\@creately\rxdata\src\database.ts:31:29)
    at new Service (...\src\modules\service.ts:11:19)
    at Object.<anonymous> (...\src\modules\service.ts:43:27)
    at Module._compile (module.js:649:30)
    at Module.m._compile (...\node_modules\ts-node\src\index.ts:422:23)
    at Module._extensions..js (module.js:660:10)
    at Object.require.extensions.(anonymous function) [as .ts] (...\node_modules\ts-node\src\index.ts:425:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
thani-sh commented 6 years ago

Hi @4F2E4A2E Thank you for reporting this issue. It seems like this module was used in NodeJS. RxData was designed to be used with web browsers. It depends on some features which are available in web browsers to work properly. Please let us know if this is not the case.

4F2E4A2E commented 6 years ago

Hi there, thanks for replying. I did try both versions and was hoping that it is nodejs compatible. At least it could be done with very little effort I guess.

thani-sh commented 6 years ago

Browser dependencies are:

@creately/lschannel Used to send messages to other open browser windows/tabs about changes. It uses localStorage and the storage event to do that.

localForage Used to store data, uses IndexedDB and falls back to WebSQL or localStorage if it is not available.

To add nodejs compatibility, first these dependencies have to be de-coupled from the code ( not a big effort ) and then we have to find good alternatives which will work on nodejs.

NodeJS support is not a big priority for us right now but we'll consider it for sure.