Not possible to require or import?
See original GitHub issueI switched to this maintained library from the old one. Just doing the switch, I am no longer able to use a standard const brain = require('brain.js')
(I basically just changed from brain to brain.js in the require), because the module will not be exported but put on the global window
variable.
Is there a reason for this? For now I just access the library using window.brain, but it would be nice to actually import/require the module to achieve a modern build process using e.g. webpack.
Any info on this and explanation why it is done this way would be nice.
//edit: I’m using brain inside the browser, I also tried brain.js/browser
and it is also adding brain to window instead of exporting it.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:24 (11 by maintainers)
Top Results From Across the Web
Both Require and import not working javascript - Stack Overflow
For some reason I can't figure out I'm unable to use either require or import when trying to import the Chalk package for...
Read more >JavaScript require vs import - Flexiple
One of the major differences between require() and import() is that require() can be called from anywhere inside the program whereas import() ...
Read more >JavaScript Require vs. Import - Bits and Pieces
With modern web development, we use require or import to refer to JavaScript dependencies. And, sometimes, we use both in combination and use ......
Read more >Compare require() vs import() in JavaScript | by Sumeet Bhalla
Both require() and import() are used to include modules. But they have several important features you should be aware of.
Read more >Detect require vs. import based on the entry point, not ... - GitHub
any instance of import during the run is now a perfectly normal "import is a reserved keyword" error. any instance of the dynamic...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe this is now resolved. @michaelsanford the library uses (at least I looked)
import { xxx } from whatever;
, (src/neural-network.js, for example) but does not inindex.js
which gets files from./dist
, which are es5.If you’d like to use the es6 files, simply use
import brain from 'brain.js/src';
orimport brain from 'brain.js/src/index';
I think.I didn’t see that till it was too late. Feel free to check the wiki, the direction, and any outstanding bugs. Committers & forks are wanted and loved.
Ty!
When using in node, I’m still getting
TypeError: brain.NeuralNetwork is not a constructor
when I doIt turns out that, for some bizzare reason, the export from
brain.js
is thisSo in order to get it working properly, you should do