[英]Unable to resolve module crypto from crypto-js (React-Native, AWS, Expo)
我正在尝试通过 react-native 和 expo 运行应用程序,并且我不断收到一个错误消息,指出它无法从 crypto-js 依赖项中解析模块加密。 我有较新版本的 crypto-js 4.0.0,据说它不应该与 react-native 应用程序一起使用,但是当其他人在他们的计算机上运行相同的应用程序时,该应用程序工作得很好。 crypto-js 甚至不在我的 package.json 中,但它嵌套在节点模块中的大约 20 个其他依赖项中。 我尝试了很多不同的解决方案,但都没有奏效。 我已经尝试进入每个嵌套依赖项和 npm 卸载新版本和 npm 安装旧版本,按照错误提示进行操作,重新克隆存储库,删除分支并创建一个新分支,然后安装 react-native-crypto ,但到目前为止没有任何效果。 它可以通过除我之外的其他人的计算机访问。 我在大约一周内无法在我的 Mac 上访问该应用程序,所以如果有人有任何解决方案或建议,我将不胜感激!
我的 package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@aws-amplify/auth": "^4.0.1",
"@aws-amplify/core": "^3.8.24",
"@expo-google-fonts/montserrat": "^0.1.0",
"@expo-google-fonts/playfair-display": "^0.1.0",
"@expo-google-fonts/yeseva-one": "^0.1.0",
"@react-native-async-storage/async-storage": "^1.15.5",
"@react-native-community/masked-view": "^0.1.11",
"@react-native-community/netinfo": "^5.9.10",
"@react-native-picker/picker": "1.9.2",
"@react-navigation/native": "^5.9.4",
"@react-navigation/stack": "^5.14.5",
"aws-amplify": "^3.4.3",
"aws-amplify-react-native": "^4.3.3",
"expo": "~40.0.0",
"expo-app-loading": "^1.0.1",
"expo-font": "~8.4.0",
"expo-status-bar": "^1.0.4",
"graphql": "^14.0.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
"react-native-animated-scroll-indicators": "^1.0.1",
"react-native-elements": "^3.4.1",
"react-native-gesture-handler": "^1.10.3",
"react-native-modal": "^11.10.0",
"react-native-modal-selector": "^2.0.3",
"react-native-multiple-select": "^0.5.6",
"react-native-picker-select": "^8.0.4",
"react-native-progress": "^4.1.2",
"react-native-reanimated": "^1.13.3",
"react-native-safe-area-context": "3.1.9",
"react-native-screens": "^2.18.1",
"react-native-vector-icons": "^8.1.0",
"react-native-web": "^0.16.3"
},
"devDependencies": {
"@babel/core": "~7.9.0"
},
"resolutions": {
"amazon-cognito-identity-js": "^4.5.1"
},
"private": true
}
错误:
Failed building JavaScript bundle.
Unable to resolve module crypto from /Users/user/proj/frontend/node_modules/@aws-amplify/auth/node_modules/crypto-js/core.js: crypto could not be found within the project.
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
21 | var CryptoJS = CryptoJS || (function (Math, undefined) {
22 |
> 23 | var crypto;
| ^
24 |
25 | // Native crypto from window (Browser)
26 | if (typeof window !== 'undefined' && window.crypto) {
尝试将 package ""aws-amplify" 降级到版本 3.3.27。执行以下步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.