升级到 Expo SDK 50 后遇到问题。当我尝试运行我的项目时,出现以下错误:
Module not found: Can't resolve 'crypto'
7 | const cryptoObject =
8 | typeof crypto === 'undefined' || typeof crypto.randomUUID === 'undefined'
> 9 | ? require('crypto')
| ^
10 | : crypto;
11 |
12 | if (!cryptoObject?.randomUUID) {
似乎没有正确找到或解析模块“crypto”。这是相关的代码片段:
import v35 from './lib/v35';
import { Uuidv5Namespace } from './uuid.types';
function uuidv4() {
// Crypto needs to be required when run in Node.js environment.
const cryptoObject = typeof crypto === 'undefined' || typeof crypto.randomUUID === 'undefined'
? require('crypto')
: crypto;
if (!cryptoObject?.randomUUID) {
throw Error("The browser doesn't support `crypto.randomUUID` function");
}
return cryptoObject.randomUUID();
}
const uuid = {
v4: uuidv4,
v5: v35('v5', 0x50, sha1),
namespace: Uuidv5Namespace,
};
export default uuid;
//# sourceMappingURL=uuid.web.js.map
我尝试寻找解决方案,但没有找到任何有效的方法。有没有人遇到过类似的问题或知道如何解决这个问题?
预先感谢您的帮助!
也许尝试删除节点模块文件夹并进行全新安装和全新构建