I must be missing a basic setup thing, but I cannot get the examples on brainJS working.
The examples mention importing a module and then creating a neural net:
import brain from 'brain.js';
const lstm = new brain.recurrent.LSTM();
But, when copy>pasting the tutorials, or trying any other path to the brain.js folder, I get this error, with brain underlined in the terminal:
import brain from 'node_modules/brain.js/index.js'
SyntaxError: Unexpected identifier
My directory structure
app.js
- node_modules (folder)
--- brain.js (folder)
------index.js
It seems that there is only a "brain.js" folder but not a file. I have tried importing with:
import brain from 'node_modules/brain.js/index.js';
import brain from 'node_modules/brain.js/';
import brain from './brain.js/index.js';
etc. etc.
Are you using Node.js? If so, I believe import isn't supported yet. If you are using Node, you should use:
const brain = require('brain.js');
I tried this and it works fine. Hope this helps.
import * as brain from 'brain.js';
Q: Why does this not work?
import brain from 'brain.js';
A: Javascript's ES6 import statement is looking for an ES6 module with a default export. Brain doesn't use this export, it makes little sense since there are more than one neural network type. Here is an example using default export:
export default {};
Q: Can imports be used with older javascript libraries?
A: Absolutely. As stated in the answer: import * as library from 'library-name';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With