medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.92k stars 2.6k forks source link

admin-bundle checking wrong directory at start up #9864

Closed turacma closed 2 weeks ago

turacma commented 2 weeks ago

Bug report

Describe the bug

When certain configuration options are used (workerMode) or when NODE_ENV is set to staging or production, server start up is checking the wrong folder. I've tried setting outdir in my medusa config, but this doesn't seem to change the behavior.

System information

Medusa version (including plugins): Node.js version: 20.15.0 Database: Postgres Operating system: Mac OS Browser (if relevant): N/A

Steps to reproduce the behavior

  1. Create a new medusa project from template
  2. Set configuration, add workerMode: "shared" to projectConfig
  3. Try to start server or run any scripts, note that the error status index.html is missing

Expected behavior

Changing parameters shouldn't change the path, or it should be configurable in a way that makes sense. Additionally, the error message should be updated to reflect the path that is being checked.

Screenshots

N/A

Code snippets

N/A

Additional context

turacma commented 2 weeks ago

Not knowing the code base intimately, it seems like this might be the issue:

https://github.com/medusajs/medusa/blob/develop/packages/medusa/src/loaders/admin.ts#L42

If I understand this correctly, any outdir set by the user will be ignored.

kasperkristensen commented 2 weeks ago

Hi @turacma, are you following the guide on how to run the standalone build that Medusa outputs in V2? You can find it here: https://docs.medusajs.com/resources/medusa-cli/commands/build#run-built-medusa-application

In V2 the medusa build command will create a standalone app in your outDir. To run the build you have to do the following:

  1. Copy your .env.production file into ./medusa/server (If you are deploying to an environment where you are reading env variables from this file).
  2. CD into ./medusa/server
  3. Install dependencies
  4. Run medusa start

Following these steps should ensure that the application starts correctly, and that the admin loader is able to locate the admin build.

turacma commented 2 weeks ago

@kasperkristensen Got it, thanks. This didn't seem to be necessary with the preview when we were setting this up, so wasn't expecting this to change.