我正在尝试通过react-native和expo运行应用程序,但我不断收到一条错误,指出它无法从crypto-js依赖项解析模块crypto。我有较新版本的 crypto-js 4.0.0,据说它不应该与反应本机应用程序一起使用,但是当其他人在他们的计算机上运行相同的应用程序时,该应用程序运行得很好。 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) {