Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Could not find index.html in the admin build directory. Make sure to run 'medusa build' before starting the server. #10147

Open
kanrio opened this issue Nov 18, 2024 · 10 comments

Comments

@kanrio
Copy link

kanrio commented Nov 18, 2024

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "latest",
    "@medusajs/cli": "latest",
    "@medusajs/framework": "latest",
    "@medusajs/medusa": "latest",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "awilix": "^8.0.1",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "latest",
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v20.16.0

Database and its version

15.7

Operating system name and version

MacOs, sonoma 14.5

Browser name

Chrome

What happended?

npm run seed or yarn seed after building with npm or yarn
error: Could not find index.html in the admin build directory. Make sure to run 'medusa build' before starting the server.
Error: Could not find index.html in the admin build directory. Make sure to run 'medusa build' before starting the server.

Expected behavior

Seeding database

Actual behavior

not seeding an error occurs
$ medusa exec ./src/scripts/seed.ts
info: Executing script at ./src/scripts/seed.ts...
info: Connection to Redis in module 'cache-redis' established
info: Connection to Redis in module 'event-bus-redis' established
info: Connection to Redis in module 'workflow-engine-redis' established
info: Connection to Redis PubSub in module 'workflow-engine-redis' established
info: Locking module: Using "in-memory" as default.
info: No job to load from /Users/x/Projects/xx/node_modules/@medusajs/medusa/dist/jobs. skipped.
error: Error running script
error: Could not find index.html in the admin build directory. Make sure to run 'medusa build' before starting the server.
Error: Could not find index.html in the admin build directory. Make sure to run 'medusa build' before starting the server.
at serve (/Users/x/Projects/xx/node_modules/@medusajs/admin-bundler/dist/index.js:1344:11)
at serveProductionBuild (/Users/x/Projects/xx/node_modules/@medusajs/medusa/src/loaders/admin.ts:75:28)
at async loadEntrypoints (/Users/x/Projects/xx/node_modules/@medusajs/medusa/src/loaders/index.ts:108:3)
at async exports.default (/Users/x/Projects/xx/node_modules/@medusajs/medusa/src/loaders/index.ts:164:31)
at async exec (/Users/x/Projects/xx/node_modules/@medusajs/medusa/src/commands/exec.ts:35:27)
error Command failed with exit code 1.

Link to reproduction repo

fresh install

@tharidlynn
Copy link

I solved this issue by adding NODE_ENV to development like this

NODE_ENV=development npm run seed

@riqwan
Copy link
Contributor

riqwan commented Nov 20, 2024

Hey @kanrio, can you confirm that your node env is development or production?

@grgmgd
Copy link

grgmgd commented Nov 20, 2024

@riqwan I have the same problem running medusa start inside docker with NODE_ENV set to production

@riqwan
Copy link
Contributor

riqwan commented Nov 20, 2024

Thanks @grgmgd, can you open a PR with the docker changes? I can take a look.

@grgmgd
Copy link

grgmgd commented Nov 20, 2024

@riqwan I tested it outside docker and the same problem happens. I just upgraded from the preview version to latest and I noticed the outDir changed to .medusa. So, I updated my tsconfig.json to match the latest default stater and the issue is still present. Am I missing something? the admin loader is trying to load the admin from src/admin instead of .medusa/server/public/admin

@riqwan
Copy link
Contributor

riqwan commented Nov 20, 2024

Let me try to reproduce, in the meantime can you share your tsconfig, package.json & medusa-config? @grgmgd

@FilioTech
Copy link

FilioTech commented Nov 24, 2024

Hi everyone,

I’ve recently started exploring Medusa and wanted to try it out, but I’ve encountered an issue. After testing with version 2.0.4, I can confirm the same problem as others have reported. Here are the details:

The issue only occurs when running with NODE_ENV=production.
The server gives the following error:

{"level":"error","message":"Could not find index.html in the admin build directory. Make sure to run 'medusa build' before starting the server.","stack":[{"columnNumber":11,"fileName":"/var/www/backend/node_modules/@medusajs/admin-bundler/dist/index.js","functionName":"serve","lineNumber":1344,"methodName":null,"native":false,"typeName":null},{"columnNumber":28,"fileName":"/var/www/backend/node_modules/@medusajs/medusa/src/loaders/admin.ts","functionName":"serveProductionBuild","lineNumber":75,"methodName":null,"native":false,"typeName":null},{"columnNumber":3,"fileName":"/var/www/backend/node_modules/@medusajs/medusa/src/loaders/index.ts","functionName":"async loadEntrypoints","lineNumber":108,"methodName":null,"native":false,"typeName":null},{"columnNumber":31,"fileName":"/var/www/backend/node_modules/@medusajs/medusa/src/loaders/index.ts","functionName":"async exports.default","lineNumber":164,"methodName":"default","native":false,"typeName":"async exports"},{"columnNumber":50,"fileName":"/var/www/backend/node_modules/@medusajs/medusa/src/commands/start.ts","functionName":"async internalStart","lineNumber":123,"methodName":null,"native":false,"typeName":null},{"columnNumber":5,"fileName":"/var/www/backend/node_modules/@medusajs/medusa/src/commands/start.ts","functionName":"async start","lineNumber":227,"methodName":null,"native":false,"typeName":null}],"timestamp":"2024-11-24 11:33:47"}
error Command failed with exit code 1.

Key observations:

  • The server starts successfully in development mode, but the error above is thrown in production.
  • I’ve done a fresh installation and included all dependencies (listed below) for clarity.
  • Using Node.js v20.18.1.

Dependencies:

{
"@medusajs/admin-sdk": "^2.0.4",
"@medusajs/cli": "latest",
"@medusajs/event-bus-redis": "^2.0.4",
"@medusajs/framework": "latest",
"@medusajs/medusa": "latest",
"@mikro-orm/core": "5.9.7",
"@mikro-orm/knex": "5.9.7",
"@mikro-orm/migrations": "5.9.7",
"@mikro-orm/postgresql": "5.9.7",
"awilix": "^8.0.1",
"express-session": "^1.18.1",
"memorystore": "^1.6.7",
"pg": "^8.13.0"
}

if anyone has resolved this or has insights into the root cause, I’d appreciate your guidance.
Thank you in advance!

@thunderwin
Copy link

I have the same problme, I just Drop "

// NODE_ENV: 'production',
"

for now.. I dont know how to solve it!

@Saboor-Hakimi
Copy link

updating your build script to medusa build && ln -s .medusa/server/public/ public will fix this issue

"scripts": {
    "build": "medusa build && ln -s .medusa/server/public/ public",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "NODE_ENV=production medusa start -H 0.0.0.0",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  }

@rafalkukla
Copy link

@Saboor-Hakimi awesome! Yep, server start in production!
Now, I seems to have 401 (Unauthorized) issue while trying to login. Didn't have that in dev. I'll have to investigate!

Thanks!

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

No branches or pull requests

8 participants