Bug: TextDecoder doesn’t exist in React Native environment

未关闭
#13 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

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

调研方向

首先阅读 node_modules/uint8array-tools/src/mjs/browser.js,并在报告中的 React Native 0.79.0 iOS 或 Android 环境中重现缺少 TextDecoder 的错误。检查如何使用 text-encoding 包而不影响浏览器或 Node.js 的行为;当该包在两个平台上都能正常工作且没有运行时错误时,即视为完成。

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

描述

When using uint8array-tools in a React Native 0.79.0 project, the following error occurs at runtime:
Uncaught Error: Property 'TextDecoder' doesn't exist

browser.js:12:21
const DECODER = new TextDecoder();
                 ^ Property 'TextDecoder' doesn't exist

Affected file:
node_modules/uint8array-tools/src/mjs/browser.js

Possible Cause

React Native does not provide TextEncoder or TextDecoder in the global environment.
As a result, libraries that depend on them (like this one) will throw errors when used outside of Node.js or browsers.

This can be mitigated by adding a small polyfill using the text-encoding
package.

Suggested Fix:

Add a conditional polyfill at the top of browser.js (or detect the React Native environment and import text-encoding only when needed).

import 'text-encoding'

Environment

React Native: 0.79.0

uint8array-tools: latest npm version

Platform: iOS (also occurs on Android)

主要语言
JavaScript
星标
1
派生
3
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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