我试图通过react-native和expo运行一个应用程序,但我一直收到一个错误,说它无法从crypto-js依赖中解析模块crypto。我有较新版本的crypto-js 4.0.0,它应该不能与react-native应用程序一起工作,但当其他人在他们的计算机上运行相同的应用程序时,该应用程序工作得很好。crypto-js甚至不在我的package.json中,但它嵌套在node-module中的大约20个其他依赖项中。我尝试了许多不同的解决方案,但都没有奏效。除了我之外,所有人的电脑都可以访问它。我已经有一周没有在我的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) {
发布于 2021-06-13 03:25:28
尝试将软件包""aws-amplify“”降级到版本3.3.27。执行以下步骤。
https://stackoverflow.com/questions/67913994
复制相似问题