Open judeantony opened 6 years ago
per the readme of this repo
Crypto is not shimmed and and we just provide the commonjs one from browserify and it will likely not work, if you really want it please pass {crypto: true} as an option.
sorry, you're better off browserifing uuid and then bringing that in or shimming it somehow to just grab the randomBytes
module somehow
We are facing the same problem, but the uuid module is being included by some other module that we are using. I thought there should be a way of marking 'crypto' as 'external', such that the require('crypto') statements would be ignored, and then use the 'globals' list to map 'crypto' references to what 'builtins({ crypto: true }' brings in (cryptoBrowserify?, e.g., map things such that a reference to crypto.functionName() becomes cryptoBrowserify.functionName() or something similar). However, we can't seem to get any combination of stuff that we've tried to work. Browserifying uuid or shimming it won't work in our case because it is referenced by some other module that is being included indirectly. @calvinmetcalf, do you have any other suggestions?
For replication purposes, I'm having the same problems described by @hanginwithdaddo. My specific use case is trying to bundle pouchdb-browser
, which requires uuid
. Enabling the { crypto: true }
option fixes this error:
Uncaught TypeError: crypto.randomBytes is not a function
But yields this error instead:
Uncaught TypeError: Cannot read property 'pbkdf2Sync' of undefined
The latter error references this line: https://github.com/crypto-browserify/pbkdf2/blob/d7882f117fa5eab9b80c5e53843f8d611c5ffc5d/index.js#L7
It looks like some kind of deep circular reference? Where crypto-browserify's pbkdf2 package requires the node crypto instead of crypto-browserify? I probed both repositories and can't seem to find a relevant issue to link here.
I tried messing around with rollup-plugin-replace
to force all references to require('crypto')
to change to require('crypto-browserify')
, but that didn't seem to help (total rollup n00b here).
... and for anyone reaching this via Google, here's a temporary workaround until this is fixed:
EDIT: as of 2 May 2018, this workaround no longer appears to be necessary; the above errors seem to have been fixed
npm install rollup-plugin-replace randombytes
In your rollup.config.js
file:
import replace from 'rollup-plugin-replace';
export default [
...
{
...
plugins: [
replace({
include: ['node_modules/uuid/**'],
delimiters: ['', ''],
values: {
'crypto.randomBytes': 'require(\'randombytes\')'
}
}),
resolve({ ... }),
commonjs(),
builtins(), // Note: do NOT include the { crypto: true } option here!
globals(),
...
]
...
}
...
];
I'm using
UUID
module to generate a random number which uses the nodeJS built in crypto module. Looks like this plugin is not able to resolve all therequire
done by the modules that are dependencies of uuid.A repro of what I'm trying to explain.
My rollup-config looks like this.
With this when I run the application I get below error in my browser console.
Following the error, I went on commenting certain lines in the index.js of crypto-browserify in node-modules to find that plugin was finally able to work as expected. Find below the commented lines in the file. It would be great if this plugin finds a way to fix this issue.