medusa: First install, storefront network error
Hello,
i did a fresh installation, follow the instruction, all good, no error. First launch storefront using nextjs, and shows following error.
`Unhandled Runtime Error
Error: Network Error Call Stack createError node_modules/axios/lib/core/createError.js (16:0) handleError node_modules/axios/lib/adapters/xhr.js (99:0)`
The attached screenshot shows as below. How could i fix the issue? Thank you.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 23 (5 by maintainers)
I’d already tried that. Here’s my medusa-config.js.
Yesterday I updated medusa npm package to the dev version, used example storefront, and I still get the same error. Does anyone know a solution for this problem?
Hi @blackyzero,
It is difficult to say without seeing what request is causing the error, you can see this in networks tab in your browsers developer tools. A guess would be that the error is due to a CORS error. It appears as you are running the Next.js starter on
10.0.0.38:8000
but the CORS variableconst STORE_CORS
is set tolocalhost:8000
in medusa-config.js try changing that value and see if that solves the problem 😃I want to share here my solution to the error below as I see it is mentioned here in some comments.
Access to XMLHttpRequest at ‘http://localhost:9000/store/products’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
STORE_CORS
variable is initially set toprocess.env.STORE_CORS || "http://localhost:3000"
which means it will take the value from env variable if that exists and is true, so instead what I did, I just changed STORE_CORS to “localhost:3000”(which is the client from where I make requests to the server).By the way, in medusa-config.js it is pretty clear commented, but I somehow didn’t payed attention initially.
So, in your backend, in medusa-config.js file:
change STORE_CORS to your client localhost. In my case it was 3000.
Hope that helps!
I’m running an application in a Docker container based on the repository https://github.com/medusajs/docker-medusa. I’ve encountered an unhandled runtime error with the following call stack:
Docker Compose
Dockerfile
develop.sh
I wanted to report this issue so it can be addressed and resolved. Thank you for your attention to this matter.