Ethers.js: Missing String.prototype.normalize (React-Native)

Created on 12 Oct 2018  路  16Comments  路  Source: ethers-io/ethers.js

wechatimg173
"dependencies": {
"ethers": "^4.0.4",
"react": "16.5.0",
"react-native": "^0.57.0",
"react-navigation": "^2.14.2"
},
"devDependencies": {
"@babel/plugin-proposal-decorators": "^7.0.0",
"babel-jest": "23.6.0",
"babel-preset-react-native": "^4.0.1",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.45.3",
"react-test-renderer": "16.5.0"
},

I used the production wallet to report an error, but when I opened 'debug js remotely' I was successful and hoped to solve it.

discussion

Most helpful comment

Can you see if the following fixes your issue?

Install into your RN package:

npm install unorm

And in your app.js, add:

import "unorm";

This should polyfil the missing functionality. I guess React Native is using a very old version of node for its V8 engine?

All 16 comments

React Native is using a very old version of node, so it is missing several feature. I鈥檓 working on a shim for RN peeps.

For normalize though, check out the test for the unorm library, which will add normalize to the String prototype.

V3.0.15 can be used on the RN, but some Caton, I look forward to the release of the RN version, because there is no better plug-in to adapt to the RN, I am looking forward to the application of this plug-in to the RN.

+1 also having this error here.

downgrading ethers to ^3.0.27 seems to work fine.

@sianlasaga Thanks! Downgrade to ^3.0.27 solves the problem.

(For anyone who happens to stumble, here is the v3 documentation of ethersJS: https://docs.ethers.io/ethers.js/v3.0/html/)

Can you see if the following fixes your issue?

Install into your RN package:

npm install unorm

And in your app.js, add:

import "unorm";

This should polyfil the missing functionality. I guess React Native is using a very old version of node for its V8 engine?

Can confirm. Adding unorm also fixes the issues.

Thank you very much! :+1:

Heya! So, I think I've solved the RN issues... Can you upgrade to 4.0.9 and try:

// Import the required shims
import 'ethers/dist/shims.js';

// Import the ethers library
import { ethers } from 'ethers';

Notes: https://docs.ethers.io/ethers.js/html/cookbook-react.html

The new shims in 4.0.10 should fix this in React Native. :)

Please try it out and let me know.

I鈥檝e heard from a few people now that the shins.js has resolved their Haste issues. If this is still a problem though, please re-open.

Thanks! :)

Hi every body, use new shim of etherjs create hdNode very slow.

@bachlongkocanh How slow? Also, which operation is slow? The derivePath, fromExtendedKey or instantiation?

@ricmoo I use derivePath.
my code:
var Path = "m/44'/60'/0'/0/0"; var seed = ethers.utils.HDNode.mnemonicToSeed(wordlist); let hdNode = ethers.utils.HDNode.fromMnemonic(wordlist); let node = hdNode.derivePath(Path);

ezgif-2-75cf8d967e94
I run on Android and it shows that error @ricmoo

@bachlongkocanh You will need to include the shims to provide support for String.prototype.normalize. Check out the shims.js in the dist/ folder. :)

File shim.js in the dist/ folder
Screen Shot 2019-07-11 at 1 48 34 PM
Include file shim.js
Screen Shot 2019-07-11 at 1 49 33 PM
And function
Screen Shot 2019-07-11 at 1 50 06 PM
Tell me, where is wrong? @ricmoo

Was this page helpful?
0 / 5 - 0 ratings