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

Module not found: Error: Can't resolve 'stream' #10

Closed
abdulmanan7 opened this issue Sep 12, 2018 · 19 comments
Closed

Module not found: Error: Can't resolve 'stream' #10

abdulmanan7 opened this issue Sep 12, 2018 · 19 comments

Comments

@abdulmanan7
Copy link

I am using angular 6 when i run ng serve
this error pops

ERROR in ./node_modules/cipher-base/index.js
Module not found: Error: Can't resolve 'stream' in '/home/devspot3/Sites/d-poll/node_modules/cipher-base'
ERROR in ./node_modules/hash-base/index.js
Module not found: Error: Can't resolve 'stream' in '/home/devspot3/Sites/d-poll/node_modules/hash-base'

@calvinmetcalf
Copy link
Contributor

what are you using to bundle the module and do you have some non-default settings related to node built in modules?

@artaommahe
Copy link

artaommahe commented Nov 10, 2018

@calvinmetcalf angular-cli disables node packages in webpack config and does not have an option for enabling

@calvinmetcalf
Copy link
Contributor

@artaommahe this sounds like It might be a problem with angular-cli then

@artaommahe
Copy link

artaommahe commented Nov 12, 2018

@calvinmetcalf it's an issue with any build pipeline that does not use default node packages. We can use universal versions instead to avoid such problems https://github.com/webpack/node-libs-browser

@calvinmetcalf
Copy link
Contributor

this was written to be part of node-libs-browser so it assumes that those are already present, if it didn't then people who used node-libs-package might get multiple versions of dependencies bundled into the app which is something we'd like to avoid.

@kyranjamie
Copy link

kyranjamie commented Jun 11, 2020

If anyone's still having issues with this, you can fix it in your Angular project using tsconfig paths to point to a browser-compatible stream lib:

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

@devdomsos
Copy link

The above didn't help for our react native project built with React. After adding solution from kyranjamie we still get the error.

@Disti4ct
Copy link

Disti4ct commented Aug 2, 2021

patch-package helped me:
npm i patch-package

in the package.json add this line:

"scripts": {
  "postinstall": "patch-package",
}

opend the problem file and correct it. In my case:
node_modules/cipher-base/index.js

var Buffer = require('safe-buffer').Buffer
var Transform = require('readable-stream').Transform // replacing instead of "stream"
var StringDecoder = require('string_decoder').StringDecoder
var inherits = require('inherits')

function CipherBase (hashMode) {
...

run the command from a root dir of your probject:
npx patch-package cipher-base

it'll create a new folder patches in the root dir and add there this fix. That's all. Commit changes. It'll automaticaly replace code in the node_modules after reinstalling packages

@santosney
Copy link

Merci j'avais un problème avec CipherBase sur mon projet j'ai modifier le package.json ..
"scripts": {
"postinstall": "patch-package",
}
puis j'ai installée le paquet via npx patch-package cipher-base.
"le problème est resolu"

@dabuchera
Copy link

patch-package helped me: npm i patch-package

in the package.json add this line:

"scripts": {
  "postinstall": "patch-package",
}

opend the problem file and correct it. In my case: node_modules/cipher-base/index.js

var Buffer = require('safe-buffer').Buffer
var Transform = require('readable-stream').Transform // replacing instead of "stream"
var StringDecoder = require('string_decoder').StringDecoder
var inherits = require('inherits')

function CipherBase (hashMode) {
...

run the command from a root dir of your probject: npx patch-package cipher-base

it'll create a new folder patches in the root dir and add there this fix. That's all. Commit changes. It'll automaticaly replace code in the node_modules after reinstalling packages

Perfect solution

@networkException
Copy link

Is this a general issue with the package or does it only occur in specific situations? I would prefer having an upstream rather than patching up the package in production.

@pszalko
Copy link

pszalko commented Nov 22, 2021

I have the same issue with webpack 5, when using pollyfils like this:

webpackConfig.resolve.fallback = {
    fs: false,                          
    crypto: require.resolve("crypto-browserify"),
    stream: require.resolve("stream-browserify")
}

I get the following error message:

index.js:11 Uncaught TypeError: Cannot read properties of undefined (reading 'call')
    at Hash.CipherBase (index.js:11)

@LuisFernandoPeretti
Copy link

patch-package helped me: npm i patch-package

in the package.json add this line:

"scripts": {
  "postinstall": "patch-package",
}

opend the problem file and correct it. In my case: node_modules/cipher-base/index.js

var Buffer = require('safe-buffer').Buffer
var Transform = require('readable-stream').Transform // replacing instead of "stream"
var StringDecoder = require('string_decoder').StringDecoder
var inherits = require('inherits')

function CipherBase (hashMode) {
...

run the command from a root dir of your probject: npx patch-package cipher-base

it'll create a new folder patches in the root dir and add there this fix. That's all. Commit changes. It'll automaticaly replace code in the node_modules after reinstalling packages

perfect!!!

steveluscher added a commit to steveluscher/cipher-base that referenced this issue Jan 16, 2022
…ebpack 5

This should fix browserify#10.
---

This library makes use of the `stream` module. This is a Node API that's no longer polyfilled by Webpack 5.

Anyone who depends upon `cipher-base` won't be able to upgrade their project to Webpack 5. Webpack will fail to build their project, citing that `stream` is missing. This also implies that anyone trying to use `cipher-base` with Create React App 5 won't be able to either, since CRA5 uses Webpack 5.

Here's an example of folks in the Web3 community having trouble with this: anza-xyz/wallet-adapter#241
steveluscher added a commit to steveluscher/cipher-base that referenced this issue Jan 16, 2022
…ebpack 5

This should fix browserify#10.
---

This library makes use of the `stream` module. This is a Node API that's no longer polyfilled by Webpack 5.

Anyone who depends upon `cipher-base` won't be able to upgrade their project to Webpack 5. Webpack will fail to build their project, citing that `stream` is missing. This also implies that anyone trying to use `cipher-base` with Create React App 5 won't be able to either, since CRA5 uses Webpack 5.

Here's an example of folks in the Web3 community having trouble with this: anza-xyz/wallet-adapter#241
steveluscher added a commit to steveluscher/cipher-base that referenced this issue Jan 16, 2022
…ebpack 5

This should fix browserify#10.
---

This library makes use of the `stream` module. This is a Node API that's no longer polyfilled by Webpack 5.

Anyone who depends upon `cipher-base` won't be able to upgrade their project to Webpack 5. Webpack will fail to build their project, citing that `stream` is missing. This also implies that anyone trying to use `cipher-base` with Create React App 5 won't be able to either, since CRA5 uses Webpack 5.

Here's an example of folks in the Web3 community having trouble with this: anza-xyz/wallet-adapter#241
@remxx
Copy link

remxx commented Mar 2, 2022

if anyone's wandered here from react/ts (me) downgrading react-scripts to 4.0.3 is the only thing that has resolved this issue

  1. update react-scripts version to 4.0.3 in your package.json
  2. rm yarn.lock package.lock; rm -rf node_modules
  3. yarn install or npm install again and restart

@owencraston
Copy link

@remxx suggestion fixed it for me 🥳 !

if anyone's wandered here from react/ts (me) downgrading react-scripts to 4.0.3 is the only thing that has resolved this issue

  1. update react-scripts version to 4.0.3 in your package.json
  2. rm yarn.lock package.lock; rm -rf node_modules
  3. yarn install or npm install again and restart

The issue for me stemmed from installing web3js. I believe by downgrading the scripts you are switching to Webpack 4 which poly fills some node core libraries.

@polarisiota
Copy link

npm i stream worked for me

@lionpunk
Copy link

lionpunk commented Apr 2, 2022

npm i stream worked for me

This works fine on the latest versions on React!

@soroushm
Copy link

while a node module exposed to web we are in trouble

ERROR in ./node_modules/cipher-base/index.js 2:16-43
Module not found: Error: Can't resolve 'stream' in '/Users/masoudsoroush/Sites/lisk-desktop/node_modules/cipher-base'

here is how we can transform a package from web pack to use alternative packages

Fallback

https://webpack.js.org/configuration/resolve/#resolvefallback

module.exports = {
  // ...the rest of your config
  resolve: {
    fallback: {
    stream: require.resolve('stream-browserify'),
    }
  }
}

Alias

if its not work for you, you can alias the packages

// webpack.config.js
module.exports = {
  // ...the rest of your config

  resolve: {
    alias: {
      'stream$': 'stream-browserify'
    }
  }
}

@calvinmetcalf here is how you can export packages for browser, thank you for you amazing job <3
https://webpack.js.org/guides/package-exports

hevelius added a commit to pagopa/io-app that referenced this issue Dec 20, 2023
## Short description
This PR adds a patch to `cipher-base` package to solve an "issue" during
proximity verification flow. It could be related on how `io-app` do the
bundle of sub-dependencies (like import/export issue). The patch is also
related to these issues on other repositories:

-
https://stackoverflow.com/questions/74413490/uncaught-typeerror-cannot-read-properties-of-undefined-reading-call-at-hash
- browserify/cipher-base#10

## List of changes proposed in this pull request
- Add patch file using patch-package

## How to test
Static checks should be enough.
@ljharb
Copy link
Member

ljharb commented Nov 16, 2024

If your bundler is working properly, it will automatically shim node builtins.

If it's broken by default, you may need to configure it to work properly.

@ljharb ljharb closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2024
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

Successfully merging a pull request may close this issue.