Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't resolve 'stream' #326

Closed
TdoubleG opened this issue Dec 27, 2018 · 9 comments
Closed

Can't resolve 'stream' #326

TdoubleG opened this issue Dec 27, 2018 · 9 comments

Comments

@TdoubleG
Copy link

TdoubleG commented Dec 27, 2018

What is wrong?

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'

Where does it happen?

When running npm start

How do we replicate the issue?

  • Fresh Project with Angular 7.1.4
  • npm install brain.js
  • npm start

How important is this (1-5)?

5

Expected behavior (i.e. solution)

Brain.js shouldn't throw this error

Other Comments

@robertleeplummerjr
Copy link
Contributor

What version of node?

@TdoubleG
Copy link
Author

TdoubleG commented Dec 27, 2018

tried with node v10.4.1 and v.11.6.0
both are throwing this error

@robertleeplummerjr
Copy link
Contributor

This is apparently a problem with angular's build system: DevExpress/devextreme-angular#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.

@TdoubleG
Copy link
Author

TdoubleG commented Dec 27, 2018

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

@jordyvanderhaegen
Copy link

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

@TdoubleG
Copy link
Author

TdoubleG commented Jan 5, 2019

Yep, that fixes the error.
Steps to fix:

  1. add the script what @jordyvanderhaegen wrotes
  2. change require("stream") to require("readable-stream") in node_modules/brain.js/dist/train-stream.js

It should work then.
I let this one open, maybe @robertleeplummerjr will find another solution.

@robertleeplummerjr
Copy link
Contributor

reproduced, I'll try and have a work around shortly.

@robertleeplummerjr
Copy link
Contributor

robertleeplummerjr commented Jan 5, 2019

Add this to tsconfig.json (found Stuk/jszip#524):

{
  "compilerOptions": {
    "paths": {
      "stream": ["./node_modules/readable-stream/readable.js"]
    }
  }
}

Add this to polyfill.ts (found partly algolia/algoliasearch-client-javascript#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.

@bitdom8
Copy link

bitdom8 commented Dec 17, 2022

This will resolve it "https://stackoverflow.com/a/73103563/12002600" npm install stream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants