cipher-base
                                
                                 cipher-base copied to clipboard
                                
                                    cipher-base copied to clipboard
                            
                            
                            
                        Module not found: Error: Can't resolve 'stream'
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'
what are you using to bundle the module and do you have some non-default settings related to node built in modules?
@calvinmetcalf angular-cli disables node packages in webpack config and does not have an option for enabling
@artaommahe this sounds like It might be a problem with angular-cli then
@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
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.
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"]
    }
  },
The above didn't help for our react native project built with React. After adding solution from kyranjamie we still get the error.
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
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"
patch-package helped me:
npm i patch-packagein 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.jsvar 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-baseit'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
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.
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)
patch-package helped me:
npm i patch-packagein 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.jsvar 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-baseit'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!!!
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
- update react-scripts version to 4.0.3 in your package.json
- rm yarn.lock package.lock; rm -rf node_modules
- yarn install or npm install again and restart
@remxx suggestion fixed it for me 🥳 !
if anyone's wandered here from react/ts (me) downgrading
react-scriptsto 4.0.3 is the only thing that has resolved this issue
- update react-scripts version to 4.0.3 in your package.json
- rm yarn.lock package.lock; rm -rf node_modules
- 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.
npm i stream worked for me
npm i streamworked for me
This works fine on the latest versions on React!
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