简体   繁体   中英

Unable to resolve module crypto from crypto-js (React-Native, AWS, Expo)

I'm trying to run an application through react-native and expo, and I keep getting an error that says that it is unable to resolve the module crypto from the crypto-js dependency. I have the newer version of crypto-js 4.0.0, which supposedly isn't supposed to work with react-native applications, but when other people run the same application on their computers, the application works just fine. crypto-js isn't even in my package.json, but it is nested in around 20 other dependencies in node-modules. I have tried so many different solutions that haven't worked. I have tried going in to each of those nested dependencies and npm uninstalling the newer version and npm installing the older version, doing as the error suggests, recloning the repository, deleting the branch and making a new one, and installing react-native-crypto, but nothing has worked so far. It's accessible through everyone else's computer except mine. I haven't been able to access the application on my Mac in about a week, so if anyone has any solutions or suggestions, I would greatly appreciate it!

my 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
}

the error:

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) {

Try downgrading the package ""aws-amplify" to version 3.3.27. Do the following steps.

  1. npm uninstall aws-amplify
  2. npm i aws-amplify@3.3.27

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM