rng-browser.js:7 Uncaught ReferenceError: global is not defined
henryavila opened this issue · 2 comments
henryavila commented
Describe the bug
When I try to generate an uuid, I get the error rng-browser.js:7 Uncaught ReferenceError: global is not defined
The code that trigger this error is
//rng-browser.js:7
var crypto = global.crypto || global.msCrypto; // for IE 11 // <<<--- THIS TRIGGER THE ERROR
if (crypto && crypto.getRandomValues) {
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
var rnds8 = new Uint8Array(16);
rng = function whatwgRNG() {
crypto.getRandomValues(rnds8);
return rnds8;
};
}
How to reproduce
npm install uuid
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ this will trigger the error
ps: The error happens for uuidv4()
and uuidv5()
. I didn't tested the others
Expected behavior
The Expected behavior is that it generate the uuid
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
Runtime
- OS: MAC OS 11.2.2
- Runtime: Node v15.2.1, Chrome (last version) and Safari (last version), Angular v11.2.3
- Typescript 4.1.5
TrySound commented
This does not look like uuid. Maybe it's some other package of version?
https://unpkg.com/browse/uuid@8.3.2/dist/esm-browser/rng.js
henryavila commented
That's my fault. Sorry.
When I added it in package.json
, i wrongley typed:
"uuid": "^3.0"
instead of "uuid": "^8.0
.
sorry for the mistake.