Installing brain.js via npm in an angular framework doesn't work.
Error:
ERROR in ./node_modules/brain.js/dist/train-stream.js
Module not found: Error: Can't resolve 'stream' in '../node_modules/brain.js/dist'
When running npm start
npm install brain.jsnpm start5
Brain.js shouldn't throw this error
What version of node?
tried with node v10.4.1 and v.11.6.0
both are throwing this error
This is apparently a problem with angular's build system: https://github.com/DevExpress/devextreme-angular/issues/776
Very odd I might add. I would like to find a solution, besides the existing "install an old package" one that seems to be the accepted norm.
Yeah saw that too.
Installing steam package leads to this error:
train-stream.js:15 Uncaught TypeError: Super expression must either be null or a function, not undefined
at _inherits (train-stream.js:15)
at train-stream.js:24
at Object../node_modules/brain.js/dist/train-stream.js (train-stream.js:165)
at __webpack_require__ (bootstrap:78)
at Object../node_modules/brain.js/index.js (index.js:6)
at __webpack_require__ (bootstrap:78)
at Module../src/app/gender/gender.component.ts (main.js:284)
at __webpack_require__ (bootstrap:78)
at Module../src/app/app.module.ts (app.component.ts:8)
at __webpack_require__ (bootstrap:78)
_inherits @ train-stream.js:15
(anonymous) @ train-stream.js:24
./node_modules/brain.js/dist/train-stream.js @ train-stream.js:165
__webpack_require__ @ bootstrap:78
./node_modules/brain.js/index.js @ index.js:6
__webpack_require__ @ bootstrap:78
./src/app/gender/gender.component.ts @ main.js:284
__webpack_require__ @ bootstrap:78
./src/app/app.module.ts @ app.component.ts:8
__webpack_require__ @ bootstrap:78
./src/main.ts @ main.ts:1
__webpack_require__ @ bootstrap:78
0 @ main.ts:12
__webpack_require__ @ bootstrap:78
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.js:1
That is what I get when I change require("stream") to require("readable-stream")
caught ReferenceError: process is not defined
at Object../node_modules/process-nextick-args/index.js (index.js:3)
at __webpack_require__ (bootstrap:78)
at Object../node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:26)
at __webpack_require__ (bootstrap:78)
at Object../node_modules/readable-stream/readable-browser.js (readable-browser.js:1)
at __webpack_require__ (bootstrap:78)
at Object../node_modules/brain.js/dist/train-stream.js (train-stream.js:10)
at __webpack_require__ (bootstrap:78)
at Object../node_modules/brain.js/index.js (index.js:6)
at __webpack_require__ (bootstrap:78)
./node_modules/process-nextick-args/index.js @ index.js:3
__webpack_require__ @ bootstrap:78
./node_modules/readable-stream/lib/_stream_readable.js @ _stream_readable.js:26
__webpack_require__ @ bootstrap:78
./node_modules/readable-stream/readable-browser.js @ readable-browser.js:1
__webpack_require__ @ bootstrap:78
./node_modules/brain.js/dist/train-stream.js @ train-stream.js:10
__webpack_require__ @ bootstrap:78
./node_modules/brain.js/index.js @ index.js:6
__webpack_require__ @ bootstrap:78
./src/app/gender/gender.component.ts @ main.js:284
__webpack_require__ @ bootstrap:78
./src/app/app.module.ts @ app.component.ts:8
__webpack_require__ @ bootstrap:78
./src/main.ts @ main.ts:1
__webpack_require__ @ bootstrap:78
0 @ main.ts:12
__webpack_require__ @ bootstrap:78
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.js:1
Ran into the same issue, got it temporarily fixed by adding the following to my index.html :
<script>
var global = global || window;
var Buffer = Buffer || [];
var process = process || {
env: { DEBUG: undefined },
version: []
};
</script>
Yep, that fixes the error.
Steps to fix:
require("stream")to require("readable-stream") in node_modules/brain.js/dist/train-stream.jsIt should work then.
I let this one open, maybe @robertleeplummerjr will find another solution.
reproduced, I'll try and have a work around shortly.
Add this to tsconfig.json (found https://github.com/Stuk/jszip/issues/524):
{
"compilerOptions": {
"paths": {
"stream": ["./node_modules/readable-stream/readable.js"]
}
}
}
Add this to polyfill.ts (found partly https://github.com/algolia/algoliasearch-client-javascript/issues/691, and above, ty @jordyvanderhaegen):
const w = (window as any);
w.process = {
env: { DEBUG: undefined },
};
w.Buffer = [];
w.process = { env: { DEBUG: undefined }, version: [] };
w.global = w;
I installed this locally and was able to have the app simply work.
Most helpful comment
Ran into the same issue, got it temporarily fixed by adding the following to my index.html :
<script> var global = global || window; var Buffer = Buffer || []; var process = process || { env: { DEBUG: undefined }, version: [] }; </script>https://stackoverflow.com/questions/50356408/upgrading-to-angular-6-x-gives-uncaught-referenceerror-global-is-not-defined