lowdb icon indicating copy to clipboard operation
lowdb copied to clipboard

LowDB with Angular 2

Open thegrid22593 opened this issue 9 years ago • 6 comments

Been trying to get LowDB working with Angular 2.

I am loading the scripts globally before my app-root is bootstrapped.

<script src="https://unpkg.com/lodash@4/lodash.min.js"></script>
  <script src="https://unpkg.com/lowdb/dist/lowdb.min.js"></script>
  <script>
  var db = low('db');
</script> 

However I am getting a runInContext error.

Uncaught TypeError: Cannot read property 'runInContext' of undefined
    at t.exports (lowdb.min.js:2)
    at (index):17

Has anyone been able to get this working with Angular 2? I am only trying to make one json file writable without using any server side code for a small local project I am working on that would always stay off a server.

Thoughts?

thegrid22593 avatar Feb 07 '17 23:02 thegrid22593

Same error here, but I import the module

import * as low from 'lowdb';

Now it seems that they removed the typescript definition

dannielarriola avatar Feb 08 '17 03:02 dannielarriola

@dannielarriola just tried importing the module and I get the same error. I have also tried loading the files globally in the scripts array in the angular-cli.json as the documentation for Angular recommends. Not luck there either.

thegrid22593 avatar Feb 08 '17 23:02 thegrid22593

Hi,

For the moment, I would suggest using https://unpkg.com/[email protected]/dist/lowdb.min.js which works and the API is almost the same as in v0.15. You shouldn't have too much trouble switching from one to another.

Actually v0.15 has just been released yesterday, so there are bugs.

I hope to be able to fix them by the end of the week and give you more feedback.

Thanks for the reports :+1:

typicode avatar Feb 08 '17 23:02 typicode

@typicode Thanks! I will give that a shot and let you know if I run into any walls.

thegrid22593 avatar Feb 08 '17 23:02 thegrid22593

Actually, it was simpler than expected to fix this issue.

It should be better with v0.15.4 https://jsfiddle.net/typicode/4kd7xxbu/

typicode avatar Feb 08 '17 23:02 typicode

@dannielarriola for TypeScript, to be honest, I would have liked to keep it in the repository but I'm not experienced enough with the language and couldn't find the time to be able to maintain it correctly and at the same time work on lowdb code.

So rather than having an out of sync definition or incomplete, I preferred to remove it.

That said, it could go in https://github.com/DefinitelyTyped/DefinitelyTyped

typicode avatar Feb 10 '17 12:02 typicode