browserify / browserify/randombytes
`global` Reference Error in Browser Environment
- Langage dominant
- JavaScript
- Étoiles
- 102
- Forks
- 47
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
When using `randombytes@2.1.0` in a browser environment with Vite as the build tool, the following error occurs:
```bash
Uncaught ReferenceError: global is not defined
```
This error stems from the browser.js implementation attempting to access the `global` object which is not available in browser DOM environments:
```javascript
var Buffer = require('safe-buffer').Buffer
var crypto = global.crypto || global.msCrypto
```
As the source code mentioned below `crypto` is defined correctly
https://github.com/browserify/randombytes/blob/b4eb4126fccc503e375853ca7b3e96aaa34af9e6/browser.js#L15-L16
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par browser.js dans l’implémentation liée et reproduisez l’échec en utilisant randombytes@2.1.0 dans un environnement de navigateur construit avec Vite. Suivez l’initialisation de crypto côté navigateur et vérifiez que le build ne génère plus "global is not defined" tout en continuant à accéder à l’implémentation de crypto du navigateur.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- web-dev
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100