React native Nanoid可以';不能在本机中使用

React native Nanoid可以';不能在本机中使用,react-native,nanoid,React Native,Nanoid,我不知道在react native中使用nanoid包时到底发生了什么,下面显示了某种错误。我不确定 我希望有人能从这个社区得到帮助 提前谢谢 场景:我只是导入到nanoid包中 import { nanoid } from 'nanoid'; 问题已解决 我已通过使用以下函数解决了此问题 因此,我认为在nanoid使用的crypto模块中,因此在react native中它不存在 为此,我们需要使用nanoid/非安全的模块。下面我还使用了customAlphabet方法 最后它成功了。:)

我不知道在react native中使用nanoid包时到底发生了什么,下面显示了某种错误。我不确定

我希望有人能从这个社区得到帮助

提前谢谢

场景:我只是导入到nanoid包中

import { nanoid } from 'nanoid';

问题已解决

我已通过使用以下函数解决了此问题

因此,我认为在
nanoid
使用的
crypto
模块中,因此在
react native
中它不存在

为此,我们需要使用
nanoid/非安全的
模块。下面我还使用了
customAlphabet
方法

最后它成功了。:)


您以前尝试过导入
react native get random values
吗?刚刚安装,我将尝试一下,现在让您知道它出现了新错误:(错误:需要模块“node\u modules\react native get random values\getrandom base64.js”,这引发了一个异常:TypeError:null不是一个对象(计算“\uu$$\u REQUIRE(\u dependencyMap[0],“react native”).NativeModules.RNGetRandomValues.getRandomBase64')注册表中的节点\u modules\react native\Libraries\LogBox\LogBox.js:148:8错误中的节点\u modules\react native\Libraries\LogBox.js:59:8错误中的节点\u modules\react native\Libraries\LogBox\LogBox.js:33:4错误中的节点\u modules\expo\build\environment\react native logs.fx.js:27:4我很高兴您找到了pro的解决方案问题。但是,不应将实际答案/解决方案编辑到您的问题中。一般来说,您应该通过回答问题来澄清问题,但不要将答案包含在问题中。您应该使用用于解决问题的代码/解决方案创建自己的答案,然后接受它(系统可能需要48小时的延迟).当你自己解决问题后。
Error: React Native does not have a built-in secure random generator. If you don’t need unpredictable IDs use `nanoid/non-secure`. For secure IDs, import `react-native-get-random-values` before Nano ID.    
at node_modules\react-native\Libraries\LogBox\LogBox.js:148:8 in registerError
at node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
at node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:104:6 in reportException
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:171:19 in handleException
at node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError
at node_modules\react-native\Libraries\polyfills\error-guard.js:49:36 in ErrorUtils.reportFatalError   
at node_modules\metro\src\lib\polyfills\require.js:204:6 in guardedLoadModule
at http://192.168.43.19:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&minify=false:203661:3 in global code
import { customAlphabet } from 'nanoid/non-secure'; 

const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 10);