Baroshem / nuxt-medusa

🛍️ Medusa module for Nuxt
https://nuxt-medusa.vercel.app
MIT License
130 stars 10 forks source link

Error 500 : Request failed with status code 404 #33

Closed Corentin7301 closed 10 months ago

Corentin7301 commented 10 months ago

Version

nuxt-medusa 0.5.0 nuxt: 3.8.2 node: 21.1.0

Reproduction Link

➡️ https://github.com/Corentin7301/medusa-test-1

Steps to reproduce

I simply followed the tutorial available here : https://nuxt-medusa.vercel.app/getting-started/setup and in Medusa blog. I've tested in SSR: true, like actually on repo AND in SSR: false with snippet available on tutorial, I've the same error.

  1. Run Medusa with pnpm dev
  2. Connect database
  3. Add product
  4. Run Nuxt with pnpm dev

What is Expected?

Look at products on index page.

What is actually happening?

Have error 500 : Request failed with status code 404

CleanShot 2023-11-27 at 19 27 48@2x

dimitrio-m commented 10 months ago

Hello @Corentin7301, I tried your link in a VM and it works ok. I get what the index pages should render.

image

Make sure you don't have any errors executing Medusa, or please share the terminal output for both the medusa server and the nuxt server.

Corentin7301 commented 10 months ago

Hi @dimitrio-m ! Thanks for your quick response!

I confess I don't understand why you don't have my error...

I looked at my Nuxt terminal and this is the error it shows:

[nuxt] [request error] [unhandled] [500] Request failed with status code 404
  at createError (./node_modules/.pnpm/axios@0.24.0/node_modules/axios/lib/core/createError.js:16:15)
  at settle (./node_modules/.pnpm/axios@0.24.0/node_modules/axios/lib/core/settle.js:17:12)
  at IncomingMessage.handleStreamEnd (./node_modules/.pnpm/axios@0.24.0/node_modules/axios/lib/adapters/http.js:293:11)
  at IncomingMessage.emit (node:events:531:35)
  at endReadableNT (node:internal/streams/readable:1696:12)
  at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
[Vue Router warn]: No match found for location with path "/api/products"
[Vue Router warn]: No match found for location with path "/api/products"
[Vue Router warn]: No match found for location with path "/api/products"
[Vue Router warn]: No match found for location with path "/api/products"

My two servers (Nuxt + Medusa) are currently running locally on MacOS M1. Nuxt : http://localhost:3000 Medusa : http://localhost:7001

Here's a screenshot of my Vue console, showing that it doesn't pick up products:

CleanShot 2023-11-28 at 13 55 50@2x

dimitrio-m commented 10 months ago

It seems that you are not connecting to the Medusa server. Are you sure the Medusa server is running without errors? If you can, please share the terminal output of the Medusa server too. Also make sure that the database has products to query too. If the database does not have products you can run pnpm run seed in the medusa directory to fill the database with demo data.

Corentin7301 commented 10 months ago

Medusa products:

CleanShot 2023-11-28 at 14 59 40@2x

Nuxt .env content: MEDUSA_URL=http://localhost:7001

Medusa in terminal after pnpm dev:

cross-env npm run build:server && medusa develop

> medusa-starter-default@0.0.1 build:server
> cross-env npm run clean && tsc -p tsconfig.server.json

> medusa-starter-default@0.0.1 clean
> cross-env ./node_modules/.bin/rimraf dist

Successfully compiled 0 files with Babel (3ms).
14:56:40 [@medusajs/admin] Started development server on http://localhost:7001/
[medusa-config] ⚠️ redis_url not found. A fake redis instance will be used.
[medusa-config] ⚠️ jwt_secret not found. fallback to either cookie_secret or default 'supersecret'.
[medusa-config] ⚠️ cookie_secret not found. fallback to either cookie_secret or default 'supersecret'.
info:    Using fake Redis
✔ Models initialized – 27ms
⠋ Initializing plugin models
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:7001/
<i> [webpack-dev-server] On Your Network (IPv4): http://192.168.1.101:7001/
<i> [webpack-dev-server] On Your Network (IPv6): http://[fe80::1]:7001/
<i> [webpack-dev-server] Content not from webpack is served from '/Users/corentinperroux/Documents/dev.nosync/Lab/medusa-test-1/medusa/public' directory
✔ Plugin models initialized – 96ms
✔ Strategies initialized – 54ms
✔ Database initialized – 132ms
✔ Repositories initialized – 43ms
✔ Services initialized – 51ms
⠋ Initializing modules
✔ Modules initialized – 291ms
✔ Express intialized – 3ms
⠋ Initializing plugins
⠙ Initializing plugins
✔ Plugins intialized – 1050ms
✔ Subscribers initialized – 53ms
✔ API initialized – 758ms
⠸ Initializing defaults
⠼ Initializing defaults
warn:    You don't have any notification provider plugins installed. You may want to add one to your project.
✔ Defaults initialized – 545ms
⠋ Initializing search engine indexing
✔ Indexing event emitted – 8ms
✔ Server is ready on port: 9000 – 29ms
<i> [webpack-dev-middleware] wait until bundle finished: /store/products
<i> [webpack-dev-middleware] wait until bundle finished: /store/products
assets by path *.js 55.7 MiB 26 assets
assets by path public/ 1.99 MiB
  asset public/locales/tm/translation.json 193 KiB [emitted] [from: node_modules/.pnpm/@medusajs+admin-ui@2.1.9_@medusajs+medusa@1.18.0_@types+node@17.0.45_@types+react@18.2.38_css_comdrdwvet3bmziw5ewi6lksg4/node_modules/@medusajs/admin-ui/ui/public/locales/tm/translation.json] [copied]
  + 15 assets
assets by path *.ttf 1.24 MiB
  asset 442f6a4cc2f03aaf41f6.ttf 398 KiB [emitted] [immutable] [from: .cache/admin/src/fonts/Inter-SemiBold.ttf] (auxiliary name: main)
  + 4 assets
assets by path *.css 302 KiB
  asset main.css 229 KiB [emitted] (name: main)
  + 2 assets
assets by path images/*.svg 2.33 KiB
  asset images/icon-plus-gray.svg 1.46 KiB [emitted] [from: node_modules/react-nestable/dist/styles/icon-plus-gray.svg] (auxiliary id hint: vendors)
  asset images/icon-minus-gray.svg 884 bytes [emitted] [from: node_modules/react-nestable/dist/styles/icon-minus-gray.svg] (auxiliary id hint: vendors)
asset index.html 437 bytes [emitted]
Entrypoint main 11.1 MiB (1.24 MiB) = runtime~main.bundle.js 142 KiB main.css 229 KiB main.bundle.js 10.8 MiB 5 auxiliary assets
orphan modules 1.67 MiB (javascript) 1.24 MiB (asset) 15.2 KiB (runtime) [orphan] 849 modules
runtime modules 83.9 KiB 49 modules
modules by path ./node_modules/ 10.5 MiB (javascript) 26.2 KiB (css/mini-extract)
  javascript modules 10.5 MiB 2222 modules
  css modules 26.2 KiB 2 modules
  ./node_modules/.pnpm/node_modules/axios/package.json 1.92 KiB [built] [code generated]
modules by path ./.cache/admin/src/ 8.76 MiB (javascript) 155 KiB (css/mini-extract)
  javascript modules 8.76 MiB 788 modules
  css modules 155 KiB
    css ./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/dist/cjs.js!./.cache/admin/src/assets/styles/global.css 155 KiB [built] [code generated]
    css ./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/dist/cjs.js!./.cache/admin/src/domain/product-categories/styles/product-categories.css 365 bytes [built] [code generated]
modules by path ./*.inspect (ignored) 30 bytes
  ./util.inspect (ignored) 15 bytes [built] [code generated]
  ./util.inspect (ignored) 15 bytes [built] [code generated]
webpack 5.89.0 compiled successfully in 14525 ms
<i> [webpack-dev-middleware] wait until bundle finished
<i> [webpack-dev-middleware] wait until bundle finished
assets by status 3.52 MiB [cached] 26 assets
assets by status 55.7 MiB [emitted]
  assets by path *.js 55.7 MiB
    assets by chunk 19.9 MiB (id hint: vendors)
      asset vendors-node_modules_pnpm_tanstack_react-table_8_10_7_react-dom_18_2_0_react_18_2_0_node_modu-2aa839.chunk.js 9.52 MiB [emitted] [minimized] (id hint: vendors)
      + 7 assets
    assets by chunk 10.8 MiB (name: main)
      asset main.bundle.js 10.8 MiB [emitted] [minimized] (name: main)
      asset main.4623798da04b7ee759d7.hot-update.js 2.15 KiB [emitted] [immutable] [hmr] [minimized] (name: main)
    assets by chunk 143 KiB (name: runtime~main)
      asset runtime~main.bundle.js 142 KiB [emitted] [minimized] (name: runtime~main)
      asset runtime~main.4623798da04b7ee759d7.hot-update.js 1.01 KiB [emitted] [immutable] [hmr] [minimized] (name: runtime~main)
    + 16 assets
  asset index.html 437 bytes [emitted]
  asset runtime_main.4623798da04b7ee759d7.hot-update.json 43 bytes [emitted] [immutable] [hmr]
Entrypoint main 11.1 MiB (1.24 MiB) = runtime~main.bundle.js 142 KiB runtime~main.4623798da04b7ee759d7.hot-update.js 1.01 KiB main.css 229 KiB main.bundle.js 10.8 MiB main.4623798da04b7ee759d7.hot-update.js 2.15 KiB 5 auxiliary assets
cached modules 20.6 MiB (javascript) 181 KiB (css/mini-extract) 1.24 MiB (asset) 15.2 KiB (runtime) [cached] 3859 modules
runtime modules 38.4 KiB 21 modules
orphan modules 213 KiB [orphan] 1 module
./.cache/admin/src/assets/styles/global.css 399 bytes [built] [code generated]
webpack 5.89.0 compiled successfully in 3491 ms

I've test pnpm run seed but I've had an error...

dimitrio-m commented 10 months ago

MEDUSA_URL=http://localhost:7001

Oh! I think I saw the problem, this URL maps to the Medusa Admin frontend, you should use the API url that in this case should be http://localhost:9000 by default

Corentin7301 commented 10 months ago

Oh! Yes it's that! Okay I understand! Thank you so much for your help and your time!

dimitrio-m commented 10 months ago

No worries, happy to help!

Baroshem commented 10 months ago

Hey guys,

Amazing that you have managed to fix the issue before I looked into it!

Nice work 💚