我目前正在使用Expo CLI从头开始开发React Native应用程序。
我用AWS Amplify设置了后端。部署和拉取都完成了,一切都到位了。我在项目根目录下有amplify文件夹。我在./src文件夹下有aws-export.js。必要的库也安装好了。
因此,一切都准备好了,可以使用AWS Amplify将我的React Native项目连接到后端。
根据documentation,我导入了放大和配置。
但是在我放置了Amplify.configure(config);
这行之后,我在终端中得到了这个错误:类型错误:undefined不是对象(评估'_awsAmplify.default. configure')
所以在放这行代码时会发生这种情况:
Amplify.configure(config);
如果我注解掉这一行,一切都没问题。
App.js非常简单:
import { View, Text } from "react-native";
import Amplify from "aws-amplify";
import config from "./src/aws-exports";
Amplify.configure(config);
const App = () => {
return (
<View>
<Text>Hello World</Text>
</View>
);
};
export default App;
我认为依赖关系之间存在一些不兼容性。
这是我的包裹.json:
{
"name": "authentication",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"@aws-amplify/cli": "^10.4.1",
"@react-native-async-storage/async-storage": "^1.17.11",
"@react-native-community/netinfo": "9.3.5",
"@react-navigation/native": "^6.0.13",
"@react-navigation/native-stack": "^6.9.1",
"amazon-cognito-identity-js": "^6.0.1",
"aws-amplify": "^5.0.1",
"expo": "~47.0.3",
"expo-status-bar": "~1.4.2",
"react": "18.1.0",
"react-hook-form": "^7.39.3",
"react-native": "0.70.5",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "~3.18.0"
},
"devDependencies": {
"@babel/core": "^7.12.9"
},
"private": true
}
无论如何,还有另一个项目,它不会产生这个错误。当然,版本号在package.json中有点不同,正如你所看到的:
旧项目的包.json:
"dependencies": {
"@aws-amplify/cli": "^10.4.0",
"@react-native-async-storage/async-storage": "^1.17.10",
"@react-native-community/netinfo": "9.3.0",
"@react-native-picker/picker": "2.4.2",
"amazon-cognito-identity-js": "^5.2.12",
"aws-amplify": "^4.3.43",
"aws-amplify-react-native": "^6.0.8",
"expo": "~46.0.16",
"expo-status-bar": "~1.4.0",
"react": "18.0.0",
"react-native": "0.69.6",
"react-native-gesture-handler": "~2.5.0",
"react-native-reanimated": "~2.9.1"
},
目前我正在使用最新版本的库,我希望尽可能避免软件包降级。
有人能帮我吗?
提前感谢!
1条答案
按热度按时间dluptydi1#
最后我找到了解决办法。
我用了这个:
import Amplify from "aws-amplify";
但是Expo文档建议使用
@aws-amplify/core
而不是库aws-amplify
。因此,正确的导入如下所示:
import Amplify from "@aws-amplify/core";
而这解决了我的问题。