anandanand84 / technicalindicators

A javascript technical indicators written in typescript with pattern recognition right in the browser
MIT License
2.18k stars 563 forks source link

KerasJS is not defined #98

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi pretty straight forward install but when I run my app (I tried both in Ionic and React Native) I get the same issue:

This was the Error log in Ionic but really hope to have it installed in React Native... Thanks!

Error: Uncaught (in promise): ReferenceError: KerasJS is not defined ReferenceError: KerasJS is not defined at Object. (http://localhost:8100/build/vendor.js:119289:30530) at Object. (http://localhost:8100/build/vendor.js:119292:30) at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30) at new HomePage (http://localhost:8100/build/main.js:59:19) at createClass (http://localhost:8100/build/vendor.js:12517:20) at createDirectiveInstance (http://localhost:8100/build/vendor.js:12364:37) at createViewNodes (http://localhost:8100/build/vendor.js:13802:53) at createRootView (http://localhost:8100/build/vendor.js:13692:5) at callWithDebugContext (http://localhost:8100/build/vendor.js:15093:42) at Object.debugCreateRootView [as createRootView] (http://localhost:8100/build/vendor.js:14394:12) at c (http://localhost:8100/build/polyfills.js:3:19752) at Object.reject (http://localhost:8100/build/polyfills.js:3:19174) at NavControllerBase._fireError (http://localhost:8100/build/vendor.js:48075:16) at NavControllerBase._failed (http://localhost:8100/build/vendor.js:48068:14) at http://localhost:8100/build/vendor.js:48115:59 at t.invoke (http://localhost:8100/build/polyfills.js:3:14976) at Object.onInvoke (http://localhost:8100/build/vendor.js:4982:33) at t.invoke (http://localhost:8100/build/polyfills.js:3:14916) at r.run (http://localhost:8100/build/polyfills.js:3:10143) at http://localhost:8100/build/polyfills.js:3:20242

anandanand84 commented 6 years ago

You need keras-js for pattern detection. It is a dependency mentioned in package.json

https://github.com/anandanand84/technicalindicators/blob/master/package.json#L115 Not sure why whatever the build tools you use didnt pull that dependency.

https://github.com/transcranial/keras-js

ghost commented 6 years ago

It did install the Keras-js dependency and I even checked it was there in my node_modules... I also installed it via NPM to make sure too but still showing that error... Any idea for a fix?

anandanand84 commented 6 years ago

make sure kerasjs is loaded before the technicalindicators library and KerasJS should be global

ghost commented 6 years ago

I managed to get it to load correctly and now the only issue within React Native that is this error regarding Node Standard Library.. Which appears to be a KerasJS error. I'll post this issue there but wanted to share it with you because this would be killer to work in RN. Thanks for your help.

The package at "...\node_modules\keras-js\lib\Model.js" attempted to import the Node standard library module "fs". It failed because React Native does not include the Node standard library. Read more at https://docs.expo.io/versions/latest/introduction/faq.html#can-i-use-nodejs-packages-with-expo

anandanand84 commented 6 years ago

For now if you dont require pattern detection, you can use npm install --save-exact technicalindicators@1.0.19 which doesnt have keras js dependancy

ghost commented 6 years ago

Okay I'll give that a try. Would I still be able to use Bullish & Bearish indicators? Thanks!

anandanand84 commented 6 years ago

yes you will still be able to use bearish and bullish but not head and shoulders, double bottom and so on.

ghost commented 6 years ago

i switched to React web so i can use Keras JS and now it is telling me when I call const bullish = require('technicalindicators').bullish; in my constructor that it is an undefined function? Any thoughts? Thanks!

anandanand84 commented 6 years ago

It seems there is some problem with the build configuration when using react, did you try using vanilla javascript, It is very difficult for me help unless you create a simple minimalist project which shows the error which I can debug to help you.

ghost commented 6 years ago

Haven't tried Vanilla JS, I understand so I created this demo that emulates my problem with whats happening. Thank you very much for your help!

https://github.com/pereless360/CoinIndicators

dawadam commented 6 years ago

Hi, Same problem with Vue JS (Vue-CLI & webpack template). Just when importing technicalindicators.

import technicalindicators from 'technicalindicators'

And when using version 1.0.19, error is : ReferenceError: regeneratorRuntime is not defined

ghost commented 6 years ago

Were you able to take a look at this to see why the indicator functions were returning as undefined? https://github.com/pereless360/CoinIndicators ... Many Thanks

anandanand84 commented 6 years ago

I did look at it a little bit but could not figure out, I would suggest to just to use vanilla javscript by adding the following to the index.html

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.min.js"></script>
<script src="https://cdn.rawgit.com/transcranial/keras-js/master/dist/keras.min.js"></script>
<script src="dist/browser.js"></script>

May be if I get time I'll add those to your repo tomorrow.

ghost commented 6 years ago

I think I got it working! Minus a few errors in the console, I am able to run it now and test successfully with your examples... However does this work with historical decimal numbers under 1.0 (for ex: .0000323)? I am trying to run this cryptocurrency prices in BTC value and am getting odd results. Maybe there is a specific period for each indicator? Some clarity would be appreciated. Thanks!

anandanand84 commented 6 years ago

yes it should work with lower values.

levithomason commented 6 years ago

@pereless360 See the KerasJS docs for a little more help:

@anandanand84 Curious, why require users to expose KerasJS as a browser global? It seems more ideal to have technicalindicators transparently handle its own dependencies.

anandanand84 commented 6 years ago

@levithomason Could not build KerasJS along with this library due to this reason. https://github.com/transcranial/keras-js/issues/109 I appreciate any suggestions you have in improving and including along with the build.

anandanand84 commented 6 years ago

Kerasjs is added to the library in technicalindicators@1.1.4.