开发者问题收集

无法从“App.js”解析“aws-amplify”

2019-08-02
5358

今天,我用 Amplify 初始化了一个新的 React Native 项目。

这个问题也在这里( https://github.com/aws-amplify/amplify-js/issues/3776 ),但我不知道这里是否有人可以提供帮助。

我甚至不知道是什么导致了我所描述的问题,如果能朝着正确的方向努力,这样我就可以自己修复它,那就太好了!

在我的 app.js 中我想做:

import Amplify from 'aws-amplify';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig);

但是它显示:

Unable to resolve "aws-amplify" from "App.js"

在我的手机上它显示:

The development server returned response error code: 500

URL: http://192.168.1.15:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false

Body:
{"originModulePath":"/Users/Dion/www/movieproject-app/App.js","targetModuleName":"aws-amplify","message":"Unable to resolve module `aws-amplify` from `/Users/Dion/www/movieproject-app/App.js`: Module `aws-amplify` does not exist in the Haste module map or in these directories:\n  /Users/Dion/www/movieproject-app/node_modules\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n  1. Clear watchman watches: `watchman watch-del-all`.\n  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.\n  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.","errors":[{"description":"Unable to resolve module `aws-amplify` from `/Users/Dion/www/movieproject-app/App.js`: Module `aws-amplify` does not exist in the Haste module map or in these directories:\n  /Users/Dion/www/movieproject-app/node_modules\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n  1. Clear watchman watches: `watchman watch-del-all`.\n  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.\n  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`."}],"name":"Error","stack":"Error: Unable to resolve module `aws-amplify` from `/Users/Dion/www/movieproject-app/App.js`: Module `aws-amplify` does not exist in the Haste module map or in these directories:\n  /Users/Dion/www/movieproject-app/node_modules\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n  1. Clear watchman watches: `watchman watch-del-all`.\n  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.\n  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.\n    at ModuleResolver.resolveDependency (/Users/Dion/www/movieproject-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:183:15)\n    at ResolutionRequest.resolveDependency (/Users/Dion/www/movieproject-app/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)\n    at DependencyGraph.resolveDependency (/Users/Dion/www/movieproject-app/node_modules/metro/src/node-haste/DependencyGraph.js:283:16)\n    at Object.resolve (/Users/Dion/www/movieproject-app/node_modules/metro/src/lib/transformHelpers.js:261:42)\n    at dependencies.map.result (/Users/Dion/www/movieproject-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:399:31)\n    at Array.map (<anonymous>)\n    at resolveDependencies (/Users/Dion/www/movieproject-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:18)\n    at /Users/Dion/www/movieproject-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:269:33\n    at Generator.next (<anonymous>)\n    at asyncGeneratorStep (/Users/Dion/www/movieproject-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)"}
processBundleResult
    BundleDownloader.java:300
access$200
    BundleDownloader.java:37
onChunkComplete
    BundleDownloader.java:224
emitChunk
    MultipartStreamReader.java:76
readAllParts
    MultipartStreamReader.java:154
processMultipartResponse
    BundleDownloader.java:208
access$100
    BundleDownloader.java:37
onResponse
    BundleDownloader.java:169
execute
    RealCall.java:206
run
    NamedRunnable.java:32
runWorker
    ThreadPoolExecutor.java:1167
run
    ThreadPoolExecutor.java:641
run
    Thread.java:784

有一些建议那里:

  1. 清除 watchman 监视: watchman watch-del-all
  2. 删除 node_modules 文件夹: rm -rf node_modules && npm install .\
  3. 重置 Metro Bundler 缓存: rm -rf /tmp/metro-bundler-cache-*npm start -- --reset-cache
  4. 删除 haste 缓存: rm -rf /tmp/haste-map-react-native-packager-*

这些都不起作用:

  1. Watchman 是一个未找到的命令。
  2. 我可以删除 / ,重新安装 node_modules ;但问题仍然存在。
  3. tmp 目录不存在。
  4. tmp 目录不存在。

希望有人知道我这里遗漏了什么。

我刚刚升级了 npm 。删除了 node_modules 并重新安装了所有内容,但我遇到了完全相同的问题。

在我的 iOS 模拟器上,错误页面上有一个“额外信息”按钮,但它是空的。

aws-amplifyaws-amplify-react-native 存在于 node_modules 目录中。我会继续尝试,但我没有主意了。

我一直在尝试降级依赖项,但这让我陷入了依赖项的兔子洞,我不想这样。

我还发现,所有 aws-amplify 相关软件包都有相同的问题:

Unable to resolve "aws-amplify-react" from "App.js" Failed building JavaScript bundle.

对于 import 'amplify' 也是如此

{
  "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",
    "test": "jest --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/samples": "~3.0.3",
    "@expo/vector-icons": "^10.0.3",
    "@react-navigation/web": "^1.0.0-alpha.9",
    "aws-amplify": "^1.1.33",
    "aws-amplify-react-native": "^2.1.16",
    "expo": "^34.0.1",
    "expo-asset": "^6.0.0",
    "expo-constants": "6.0.0",
    "expo-font": "~6.0.1",
    "expo-web-browser": "6.0.0",
    "react": "16.8.3",
    "react-dom": "^16.8.6",
    "react-native": "https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz",
    "react-native-gesture-handler": "~1.3.0",
    "react-native-web": "^0.11.4",
    "react-navigation": "^3.11.0"
  },
  "devDependencies": {
    "babel-preset-expo": "^6.0.0",
    "jest-expo": "^34.0.0"
  },
  "private": true
}
1个回答

花了几个小时试图弄清楚这一点后,我将 aws-amplify 版本降级为之前与我的 expo 应用程序配合使用的版本。降级后,它运行得非常好。

我想知道为什么它之前可以工作,现在却不行了,而且似乎较新版本的 amplify 还不能与 react-native/expo 项目配合使用。

希望这能有所帮助!

Ed Reinoso
2020-04-28