React Native:<string>.matchAll 不是函数 [英] React Native: <string>.matchAll is not a function
本文介绍了React Native:<string>.matchAll 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在运行 React Native 应用程序时遇到一个奇怪的错误:
I get a weird error when running my React Native app:
一些示例代码:
const { url } = <incoming object>;
const reURL = <my regex>;
console.debug('url:', url);
console.debug('typeof url:', typeof url);
matches = [...url.matchAll(reURL)];
日志输出:
url: <as expected>
typeof url: string
错误信息:
TypeError: url.matchAll is not a function. (In 'url.matchAll(reURL)', 'url.matchAll' is undefined)
在 iOS 上一切正常,错误仅在 Android 上发生.
Everything works fine on iOS, the error only occurs on Android.
最新的环境,几天前更新了所有 npm
包.
Pretty up to date environment, updated all npm
packages a couple of days ago.
有没有人知道从哪里开始寻找解决方案?
Does anyone have the slightest idea where to even begin searching for a solution ?
推荐答案
你可以使用 string.prototype.matchall
来 polyfill.
You can use string.prototype.matchall
to polyfill.
https://www.npmjs.com/package/string.prototype.matchall
import matchAll from 'string.prototype.matchAll'
matchAll.shim()
这篇关于React Native:<string>.matchAll 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文