aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.41k stars 2.11k forks source link

I have created a profile model and I have done amplify push but I keep getting "profile model is not defined" and I don't know how to fix please help. #13603

Closed Jinyoung3 closed 1 month ago

Jinyoung3 commented 1 month ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

No response

Backend

Amplify Gen 2 (Preview)

Environment information

``` # Put output below this line ```

...

Describe the bug

I use npx expo run:ios and run on an iphone simulator and when I click on profile button and click edit profile I get profile model is not defined and no information is being saved. I don't really know what I'm doing as I am new to aws amplify so please help me and tell me what I'm doing wrong. I posted link to github repo below so you can just do git clone and the url

Expected behavior

just says Profile model is not defined correctly or Profile model is not defined or update method is not available..

Reproduction steps

...

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

you can run https://github.com/Jinyoung3/awsman.git to clone my repo and run it on your device. amplify/data/resource has model, type.ts has type. I run by doing npx expo run:ios

chrisbonifacio commented 1 month ago

Hi @Jinyoung3 👋 thanks for raising this issue.

After looking through your repo, it seems you're generating a client in different places, including the editProfile.ts file and I noticed one also in the amplify/backend/data folder.

I would recommend creating a util folder in the root directory of your project where you generate it once and export it where needed.

Give that a try and let me know if it helps.

I also noticed that you have a aws-exports file that is configuring Amplify and importing itself? If you're using Gen 2, the sandbox should have generated an amplify_outputs.json file that you can use to configure the Amplify library.

But, it seems you are configuring Amplify correctly in the App.tsx files assuming the sandbox is running and generated the amplify_outputs.json file.

Lastly, in your package.json there are scoped amplify packages like "@aws-amplify/data". These are not necessary to install. You should only have "aws-amplify" installed and can import the categories you need from its sub directories like "aws-amplify/api"

Having multiple amplify packages with different versions can lead to weird behavior and mess with configurations.

Jinyoung3 commented 1 month ago

should I move the amplify/backend/data/resource.ts into util folder in root directory and should I delete all other codes where I generate client?

Jinyoung3 commented 1 month ago

{ "name": "awsman", "version": "1.0.0", "main": "expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web" }, "dependencies": { "@react-native-async-storage/async-storage": "^1.23.1", "@react-native-community/masked-view": "^0.1.11", "@react-native-community/netinfo": "^11.3.2", "@react-native-picker/picker": "^2.7.7", "@react-navigation/native": "^6.1.17", "@react-navigation/stack": "^6.4.0", "aws-amplify": "^6.4.0", "expo": "~51.0.17", "expo-image-picker": "~15.0.7", "expo-router": "^3.5.17", "expo-status-bar": "~1.12.1", "react": "18.2.0", "react-native": "0.74.2", "react-native-gesture-handler": "^2.17.1", "react-native-get-random-values": "^1.11.0", "react-native-image-picker": "^7.1.2", "react-native-reanimated": "^3.12.1", "react-native-safe-area-context": "^4.10.7", "react-native-screens": "^3.32.0", "react-native-swipe-list-view": "^3.2.9", "react-native-url-polyfill": "^2.0.0" }, "devDependencies": { "@aws-amplify/backend": "^1.0.4", "@aws-amplify/backend-cli": "^1.1.0", "@babel/core": "^7.20.0", "@types/cookie": "^0.6.0", "@types/react": "~18.2.45", "aws-cdk": "^2.147.2", "aws-cdk-lib": "^2.147.2", "constructs": "^10.3.0", "esbuild": "^0.22.0", "tsx": "^4.16.0", "typescript": "^5.5.2" }, "private": true } that's my package.json.Also in root directory I made util directory and I put client.ts and copied code from amplify/backend/data/resource.ts and amplify push but same error. Also, do you recommend deleting all the lines that says generateclient besides the one that I just created?

chrisbonifacio commented 1 month ago

Hi @Jinyoung3 👋

It seems you opened another issue recently. Are you still experiencing this particular issue or were you able to get unblocked and are only experiencing the more recent issue?

Also, the link to the repo seems to redirect to a 404 and I can't find a react or amplify project among your public repositories.

chrisbonifacio commented 1 month ago

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!