在 React Native 中安装需要 solanaweb3js 的包会引发错误。
我发现我并不孤单但我无法让提供的解决方案为我工作。
错误:
Error: Unexpected token name «n», expected punc «,» in file node_modules/solana-test-package/node_modules/@solana/web3.js/lib/index.native.js at 4581:32
at /Users/darjusch/development/solana/wallet-sdk/node_modules/metro-transform-worker/src/index.js:279:15
at Generator.next (<anonymous>)
at asyncGeneratorStep (/Users/darjusch/development/solana/wallet-sdk/node_modules/metro-transform-worker/src/index.js:146:24)
at _next (/Users/darjusch/development/solana/wallet-sdk/node_modules/metro-transform-worker/src/index.js:168:9)
at /Users/darjusch/development/solana/wallet-sdk/node_modules/metro-transform-worker/src/index.js:175:7
at new Promise (<anonymous>)
at /Users/darjusch/development/solana/wallet-sdk/node_modules/metro-transform-worker/src/index.js:164:12
at minifyCode (/Users/darjusch/development/solana/wallet-sdk/node_modules/metro-transform-worker/src/index.js:289:17)
at Object.<anonymous> (/Users/darjusch/development/solana/wallet-sdk/node_modules/metro-transform-worker/src/index.js:569:40)
info Run CLI with --verbose flag for more details.
> Task :app:bundleReleaseJsAndAssets FAILED
FAILURE: Build failed with an exception.
重现错误: 克隆: https://github.com/Darjusch/AwesomeProject
或
npx react-native init AwesomeProject
npm i solana-test-package
我上传了 npm packge 来重现该问题: https://github.com/Darjusch/solana-test-package
这是包装内容:
index.js
const { Keypair } = require('@solana/web3.js');
export function generateKeypair() {
const keypair = Keypair.generate();
console.log(`Generated Solana publickey is ${keypair.publicKey.toBase58()}`);
return keypair;
}
package.json
"dependencies": {
"@solana/web3.js": "^1.54.0"
}
如有任何帮助!
该错误意味着您的 JavaScript 运行时不理解
BigInt
文字(例如 2n
)。像 Hermes 这样的较新的运行时大约在 React Native 0.70.0 中添加了对它们的支持。
按照更新后的 React Native 项目初始化说明进行操作:https://solanacookbook.com/integrations/react-native.html#how-to-use-solana-web3-js-in-a-react-native-app
如果您想创建去中心化加密钱包,您可以在此处查看详细信息 https://www. Fiverr.com/s/DBgA177