首页 > 解决方案 > 使用 AWS 的全栈项目,运行 yarn ios,出现错误:这些文件都不存在:从 'aws-amplify' 导入 Amplify;从 './aws-exp 导入配置

问题描述

我正在尝试使用 AWS 建立一个完整的堆栈项目,但是当我运行时

yarn ios

我收到此错误:

Unable to resolve module ./aws-exports from /Users/username/Desktop/folderLocation/index.js: 

None of these files exist:
  * aws-exports(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
  * aws-exports/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
   8 |
   9 | import Amplify from 'aws-amplify';
> 10 | import config from './aws-exports';
     |                     ^
  11 | Amplify.configure(config);
  12 |
  13 | AppRegistry.registerComponent(appName, () => App);

RCTFatal
__28-[RCTCxxBridge handleError:]_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
main
start
0x0

我使用 Amplify CLI 创建项目,其中:

amplify init

它在 src 目录中创建了一个名为 amplify 的顶级目录和一个名为 aws-exports.js 的文件。

我安装了放大库

npm install aws-amplify aws-amplify-react-native amazon-cognito-identity-js @react-native-community/netinfo

我跑了:npx pod-install ios

在 index.js 中,我输入:

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

我在一些博客(https://github.com/aws-amplify/amplify-js/issues/669)上看到我应该运行:

npm install -g awsmobile-cli@latest

因为“也许如果您使用的是旧版本的 awsmobile-cli。” 但这不会安装,我遇到了一堆错误,例如:

Missing write access to /usr/local/lib/node_modules 
The operation was rejected by your operating system.

任何帮助将不胜感激,谢谢

标签: amazon-web-services

解决方案


推荐阅读