threads icon indicating copy to clipboard operation
threads copied to clipboard

Unhandled Runtime Error

Open Tuong-Duy-Anh opened this issue 2 years ago • 16 comments

Hi guys, I'm having this error in the process of implementing updateUser() image really need your help, cause I have checked the typo and found no differents

Tuong-Duy-Anh avatar Aug 20 '23 16:08 Tuong-Duy-Anh

Hello?

Tuong-Duy-Anh avatar Aug 21 '23 15:08 Tuong-Duy-Anh

Hi could you drop a screenshots of these:

  • implement of the updateUser()
  • updateUser() method

HengKevin avatar Aug 22 '23 07:08 HengKevin

Hi, here is some code snippets:

  • Here is where I use the updateUser(): image
  • Here is where I implement the updateUser(): Which need the User variable imported from user.model.ts image
  • Here is the user.model.ts where the error occurred: image

Tuong-Duy-Anh avatar Aug 22 '23 15:08 Tuong-Duy-Anh

  • I then when on to fix the bug in the user.model by using the optional chaining (?.) operator which as follow: image
  • I then process to continue with no error until I hit the submit button, then I encounter another 2 new errors: image And image

Tuong-Duy-Anh avatar Aug 22 '23 15:08 Tuong-Duy-Anh

Another finding is on the Onboarding Form, If I don't choose the img to set my profile image, I hit the submit button but nothing happen image

Tuong-Duy-Anh avatar Aug 22 '23 16:08 Tuong-Duy-Anh

Hi, here is some code snippets:

* Here is where I use the updateUser():
  ![image](https://user-images.githubusercontent.com/94125196/262407874-9f07db3b-95e4-4e4f-bb51-2f1a6d404b85.png)

* Here is where I implement the updateUser(): Which need the `User` variable imported from user.model.ts
  ![image](https://user-images.githubusercontent.com/94125196/262408233-e68f2440-295b-4978-9b7e-051ee3c1efd0.png)

* Here is the user.model.ts where the error occurred:
  ![image](https://user-images.githubusercontent.com/94125196/262409911-ef70c1cc-5f78-4c6d-aa79-f62776f399b0.png)

for this you can try changing from: imgRes[0].fileUrl -> imgRes[0].url due to deprecation.

And you don't need to add nullable expression (?) to the { mongoose.models.User || mongoose.model("User", UserSchema). It will detect automatically whether the model exists or not, if not it will create one.

HengKevin avatar Aug 23 '23 02:08 HengKevin

Another finding is on the Onboarding Form, If I don't choose the img to set my profile image, I hit the submit button but nothing happen image

for this issue, have you try setting the condition for the userData prop in the onboarding component? This will decide whet Example: const userData = { id: user?.id, objectId: userInfo?._id, username: userInfo ? userInfo?.username : user?.username, name: userInfo ? userInfo?.name : user?.firstName || "", bio: userInfo ? userInfo?.bio : "", image: userInfo ? userInfo?.image : user?.imageUrl, };

HengKevin avatar Aug 23 '23 02:08 HengKevin

Hi, here is some code snippets:

* Here is where I use the updateUser():
  ![image](https://user-images.githubusercontent.com/94125196/262407874-9f07db3b-95e4-4e4f-bb51-2f1a6d404b85.png)

* Here is where I implement the updateUser(): Which need the `User` variable imported from user.model.ts
  ![image](https://user-images.githubusercontent.com/94125196/262408233-e68f2440-295b-4978-9b7e-051ee3c1efd0.png)

* Here is the user.model.ts where the error occurred:
  ![image](https://user-images.githubusercontent.com/94125196/262409911-ef70c1cc-5f78-4c6d-aa79-f62776f399b0.png)

for this you can try changing from: imgRes[0].fileUrl -> imgRes[0].url due to deprecation.

And you don't need to add nullable expression (?) to the { mongoose.models.User || mongoose.model("User", UserSchema). It will detect automatically whether the model exists or not, if not it will create one.

Hi, I try the following solution and it doesn't work, error bellow still insists image

Tuong-Duy-Anh avatar Aug 23 '23 14:08 Tuong-Duy-Anh

Inadition to the error, I also found a long list of Module not found: error in my VS code terminal when running the application on /onboarding route. Here are some screen shot image image image image

Tuong-Duy-Anh avatar Aug 23 '23 15:08 Tuong-Duy-Anh

Hi guys, really need your help on this

Tuong-Duy-Anh avatar Aug 25 '23 09:08 Tuong-Duy-Anh

I met the same error. Try to add 'use server' to lib/actions/user.actions.ts file to enable the server action, add

experimental: {
    serverActions: true
}

to next.config.js file, it worked for me.

rick-ame avatar Oct 01 '23 13:10 rick-ame

I met the same error. Try to add 'use server' to lib/actions/user.actions.ts file to enable the server action, add

experimental: {
    serverActions: true
}

to next.config.js file, it worked for me.

Thanks, it worked like charm. But then I counter another problem with the mongoose as follow when hit the submit button. image

Tuong-Duy-Anh avatar Oct 01 '23 15:10 Tuong-Duy-Anh

I'm using the latest next.js and I don't need the serverComponentsExternalPackages config, seems the errors are on browser, maybe you can try to add it to your next.config.js file, it would be like this

experimental: {
    serverActions: true,
    serverComponentsExternalPackages: ["mongoose"],
},

rick-ame avatar Oct 02 '23 03:10 rick-ame

I'm using the latest next.js and I don't need the serverComponentsExternalPackages config, seems the errors are on browser, maybe you can try to add it to your next.config.js file, it would be like this

experimental: {
    serverActions: true,
    serverComponentsExternalPackages: ["mongoose"],
},

Thanks for quickly response, I've already included these line on my next.config.js file when the problem occured

Tuong-Duy-Anh avatar Oct 03 '23 13:10 Tuong-Duy-Anh

In my case once use server is added to the top of my user action file everything works fine, the error still looks like your codes run on client side, maybe you can try to clean nextjs cache (remove .next folder under project root) and run again, and if use server directive works, you don't need the nullable expression for mongoose.models.User, eliminate the question mark and see if it reports error. I don't have enough information about your repo state, I'm not sure about the root cause.

rick-ame avatar Oct 04 '23 02:10 rick-ame

In my case once use server is added to the top of my user action file everything works fine, the error still looks like your codes run on client side, maybe you can try to clean nextjs cache (remove .next folder under project root) and run again, and if use server directive works, you don't need the nullable expression for mongoose.models.User, eliminate the question mark and see if it reports error. I don't have enough information about your repo state, I'm not sure about the root cause.

Thanks for your support, after trying all the mentioned solutions, errors still persist, I guess I might start all over and see if such errors keep coming up.

Tuong-Duy-Anh avatar Oct 04 '23 13:10 Tuong-Duy-Anh