Skip to content

Instantly share code, notes, and snippets.

@basir
Last active July 10, 2021 16:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basir/7e862be35529f46f473889a1943b0ff6 to your computer and use it in GitHub Desktop.
Save basir/7e862be35529f46f473889a1943b0ff6 to your computer and use it in GitHub Desktop.

Module not found: Error: Can't resolve 'fs'

add this line at the top of the file: import fs from 'fs';

Delete images on heroku after upload

it is because of heroku policy for free dyno. It delete all files after 30 mins idle. if you want to keep them you need to buy a paid dyno. get it from here: https://www.heroku.com/pricing

URL it is /product/undefined

Check why the product link does not contain the product id in HomeScreen.js and Product.js component. Your code seems right. clone this repo and run it on your computer. It works.

https://github.com/basir/amazona

Then compare your code with this.

Cast to objectid faild for value '1'

make sure you did not return static data in data.js in server.js.

clone this repo and run it on your computer. It works.

https://github.com/basir/amazona

Then compare your code with this.

New Payment Gateway

In this course, I only teach PayPal. for others you need to read the docs for node.js and react framework.

Error "SyntaxError: Cannot use import statement outside a module"

Did you use this command in this package.json? https://github.com/basir/amazona/blob/master/package.json#L9 and this in Procfile? https://github.com/basir/amazona/blob/master/Procfile#L1

Messages stay after reopenning the pages

To fix this issue we need to use a modal to show messages and user has to close it to continue. use this to wrap messages inside it: https://github.com/reactjs/react-modal

Seller Error: Can't read property name of undefined

Follow these steps to fix this error:

1- Login with this seller account and in User Profile set a name for this seller.

2- Make sure you have a user with this id (product.seller._id) or not. if you deleted that user you need to delete the product too and create it again. make sure for current user you have set the seller name in User profile.

If it does not work you can simply clone the course repo:

https://github.com/basir/amazona

Then follow this guide to run it locally:

https://github.com/basir/amazona#run-locally

Then compare your code with this.

User validation failed: isAdmin: Path isAdmin is required

to fix validation error you need to check if you set the default value for isAdmin like this in userModal.js

https://github.com/basir/amazona/blob/master/backend/models/userModel.js#L8

and also try to set isAdmin: false in register API to fix this issue:

https://github.com/basir/amazona/blob/master/backend/routers/userRouter.js#L56

Map flashes and then disappears

whether you did not set the google API key correctly or your google account on firebase is not verified.

check this please: https://developers.google.com/maps/documentation/javascript/error-messages

order.user.name: TypeError: Cannot read property 'name' of undefined

it means that user is null.

why user is null?

The user has been deleted. so you need to have a check like this:

{req.user? req.user.name:'Deleted User'}

or delete the order and create a new user and create order for them.

Deleted Item in Cart When Refresh Item in the cart

when you refresh the page at this address /cart/productid, then it adds productid to the cart again.

one simple solution is to move dispatch(addToCart(productId, qty)) from cart and product screen. so change ProductScreen.js:

 const addToCartHandler = () => {
    dispatch(addToCart(productId, 1)); // you need to import dispatch like in cart screen
    props.history.push(`/cart`);
  };

then remove this line from CartScreen.js: https://github.com/basir/amazona/blob/master/frontend/src/screens/CartScreen.js#L16-L18

Proxy Error

you get proxy error if:

Socket.io not export Server

first of all make sure you have this version of socket.io:

https://github.com/basir/amazona/blob/master/package.json#L30

the remove node engine part to use the latest node in the Heroku.

https://github.com/basir/amazona/blob/master/package.json#L37-L40

sample image does not display

for not showing images:

http://localhost:3000/images/p1.jpg

if they are ok then you should see images.

Make images from different size to same size

use this guide to make all images same size:

https://stackoverflow.com/questions/19414856/how-can-i-make-all-images-of-different-height-and-width-the-same-via-css

paytm

hello there,

Paytm is not part of this course but I found this video to interagte paytm with node apps:

https://www.youtube.com/watch?v=HQsKYj8OOGk

product not delete for seller

hello there,

yes, you are right. it is becaus of this:

https://github.com/basir/amazona/blob/master/backend/routers/productRouter.js#L150

you can change isAdmin with isSellerOrAdmin to fix it. but I don't recommend it because of security reasons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment