简体   繁体   English

无法从 crypto-js(React-Native、AWS、Expo)解析模块加密

[英]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.我正在尝试通过 react-native 和 expo 运行应用程序,并且我不断收到一个错误消息,指出它无法从 crypto-js 依赖项中解析模块加密。 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 4.0.0,据说它不应该与 react-native 应用程序一起使用,但是当其他人在他们的计算机上运行相同的应用程序时,该应用程序工作得很好。 crypto-js isn't even in my package.json, but it is nested in around 20 other dependencies in node-modules. crypto-js 甚至不在我的 package.json 中,但它嵌套在节点模块中的大约 20 个其他依赖项中。 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.我已经尝试进入每个嵌套依赖项和 npm 卸载新版本和 npm 安装旧版本,按照错误提示进行操作,重新克隆存储库,删除分支并创建一个新分支,然后安装 react-native-crypto ,但到目前为止没有任何效果。 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!我在大约一周内无法在我的 Mac 上访问该应用程序,所以如果有人有任何解决方案或建议,我将不胜感激!

my package.json我的 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.尝试将 package ""aws-amplify" 降级到版本 3.3.27。执行以下步骤。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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