browserify / browserify/randombytes

`global` Reference Error in Browser Environment

未关闭
#38 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
102
派生
47
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

这个仓库没有索引到贡献指南

调研方向

从链接的实现中的 browser.js 开始,在使用 Vite 构建的浏览器环境中使用 randombytes@2.1.0 重现该故障。跟踪浏览器端的 crypto 初始化,并验证构建不再引发 "global is not defined",同时仍能访问浏览器的 crypto 实现。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
web-dev
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。