medusajs / medusa

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

admin not showing routes and widgets #8747

Open n3cr0murl0c opened 3 months ago

n3cr0murl0c commented 3 months ago

Bug report

Describe the bug

api route and admin not showing routes and widgets while running medusa start, but they show while running medusa develop. No Errors, no alerts, nothing appears to be wrong

System information

Medusa version : "@medusajs/medusa": "^1.20.7" Node.js version: 18LTS and 20.12.2 Database: postgresql Operating system: Debian 11

Steps to reproduce the behavior

  1. Go to https://github.com/n3cr0murl0c/2k3-backend and clone the repo
  2. docker compose up --build -d
  3. Go to http://localhost:9000/app and login with medusaUser@testmail.com -p change-the-user
  4. See error at the left, should be "Banners Promocionales" before settings, and inside an order, in order.details should be a widget in order.details.before but nothing appears on productins.
  5. rundocker compose down backend and run npm run dev and go into localhost:7001 and now route and widget works.

Expected behavior

Route and widget should show in production

Screenshots

admin route in develop mode (medusa develop) Screenshot from 2024-08-23 11-38-38

api route in develop mode (medusa develop) Screenshot from 2024-08-23 11-37-55

widget working in develop mode (medusa develop) Screenshot from 2024-08-23 11-35-00

api route not working in production (medusa start) Screenshot from 2024-08-23 11-19-02

Code snippets

package.json

{
  "name": "2k3-backend",
  "version": "1.0.1",
  "description": "2k3Backend powered by medusajs",
  "author": "Medusa (https://medusajs.com)",
  "license": "UNLICENSED",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "lint": "eslint . --ext .js,.ts,.tsx,.jsx --ignore-path .eslintignore",
    "clean": "cross-env ./node_modules/.bin/rimraf dist",
    "build": " npm run build:server && npm run build:admin",
    "build:production": "npm run build",
    "build:server:production": "tsc -p tsconfig.server.json",
    "build:server": "tsc -p tsconfig.server.json",
    "build:admin:deployment": "medusa-admin build --deployment",
    "build:admin": "medusa-admin build",
    "watch": "cross-env tsc --watch",
    "test": "cross-env jest",
    "seed": "cross-env medusa seed -f ./data/seed.json",
    "start": "npm run build && medusa migrations run && medusa start",
    "start:production": "medusa migrations run && medusa start",
    "start:dev": "medusa migrations run && medusa develop",
    "start:custom": "cross-env npm run build && node --preserve-symlinks --trace-warnings index.js",
    "dev": "npm run build&& medusa develop",
    "dev:admin": "medusa-admin develop "
  },
  "dependencies": {
    "@emotion/react": "^11.11.4",
    "@emotion/styled": "^11.11.5",
    "@medusajs/admin": "^7.1.11",
    "@medusajs/admin-shared": "^0.0.2-snapshot-20230525210913",
    "@medusajs/cache-inmemory": "^1.8.9",
    "@medusajs/cache-redis": "^1.9.0",
    "@medusajs/event-bus-local": "^1.9.8",
    "@medusajs/event-bus-redis": "^1.8.11",
    "@medusajs/file-local": "^1.0.3",
    "@medusajs/medusa": "^1.20.7",
    "@medusajs/ui": "^3.0.0",
    "@medusajs/ui-preset": "^1.1.3",
    "@mui/material": "^5.15.20",
    "@react-email/components": "^0.0.19",
    "@react-email/render": "^0.0.15",
    "@tanstack/react-query": "^4.22.0",
    "body-parser": "^1.19.0",
    "connect-busboy": "^1.0.0",
    "cors": "^2.8.5",
    "cross-env": "^7.0.3",
    "dotenv": "^16.3.1",
    "express": "^4.19.2",
    "fs": "^0.0.1-security",
    "fs-extra": "^11.2.0",
    "lucide-react": "^0.424.0",
    "medusa-fulfillment-manual": "^1.1.39",
    "medusa-interfaces": "^1.3.8",
    "medusa-payment-manual": "^1.0.24",
    "medusa-payment-stripe": "^6.0.7",
    "nodemailer": "^6.9.13",
    "react-email": "^2.1.4",
    "typeorm": "^0.3.16",
    "url": "^0.11.3"
  },
  "peerDependencies": {
    "react-email": "^2.1.4"
  },
  "devDependencies": {
    "@babel/cli": "^7.14.3",
    "prettier": "^3.3.3",
    "@typescript-eslint/eslint-plugin": "^8.2.0",
    "eslint-config-prettier": "^9.1.0",
    "@typescript-eslint/parser": "^8.2.0",
    "@babel/core": "^7.14.3",
    "@babel/preset-typescript": "^7.21.4",
    "@eslint/eslintrc": "^3.1.0",
    "@eslint/js": "^9.9.0",
    "@medusajs/medusa-cli": "latest",
    "@types/express": "^4.17.13",
    "@types/fs-extra": "^11.0.4",
    "@types/jest": "^27.4.0",
    "@types/node": "^20.14.2",
    "babel-preset-medusa-package": "^1.1.19",
    "eslint": "^9.9.0",
    "eslint-plugin-prettier": "^5.2.1",
    "eslint-plugin-react": "^7.35.0",
    "globals": "^15.9.0",
    "jest": "^27.3.1",
    "rimraf": "^3.0.2",
    "standard": "^17.1.0",
    "ts-jest": "^27.0.7",
    "ts-loader": "^9.2.6",
    "typescript": "^4.5.2",
    "typescript-eslint": "^8.2.0"
  },
  "jest": {
    "globals": {
      "ts-jest": {
        "tsconfig": "tsconfig.spec.json"
      }
    },
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "testPathIgnorePatterns": [
      "/node_modules/",
      "<rootDir>/node_modules/"
    ],
    "rootDir": "src",
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
    "transform": {
      ".ts": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "./coverage",
    "testEnvironment": "node"
  },
  "trustedDependencies": [
    "core-js",
    "core-js-pure",
    "medusa-telemetry"
  ]
}

medusa-config.js

const dotenv = require('dotenv');
const { resolve } = require('path');

let ENV_FILE_NAME = '';
switch (process.env.NODE_ENV) {
  case 'production':
    ENV_FILE_NAME = '.env.production';
    break;
  case 'staging':
    ENV_FILE_NAME = '.env.staging';
    break;
  case 'test':
    ENV_FILE_NAME = '.env.test';
    break;
  case 'development':
  default:
    ENV_FILE_NAME = '.env';
    break;
}

try {
  dotenv.config({ path: process.cwd() + '/' + ENV_FILE_NAME });
} catch (e) {}

// CORS when consuming Medusa from admin
const ADMIN_CORS = process.env.ADMIN_CORS || 'http://localhost:7000,http://localhost:7001';

const MEDUSA_ADMIN_BACKEND_URL = process.env.MEDUSA_ADMIN_BACKEND_URL || 'http://localhost:9000';

// CORS to avoid issues when consuming Medusa from a client
const STORE_CORS = process.env.STORE_CORS || 'http://localhost:8000,http://localhost:7001';

const DATABASE_URL = process.env.DATABASE_URL || 'postgres://localhost/medusa-starter-default';

const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379';

const plugins = [
  `medusa-fulfillment-manual`,
  `medusa-payment-manual`,
  {
    //medusa-file-local
    resolve: `@medusajs/file-local`,
    options: {
      upload_dir: 'uploads',
      backend_url: MEDUSA_ADMIN_BACKEND_URL,
    },
  },
  {
    //medusa-admin dashboard
    resolve: '@medusajs/admin',
    /** @type {import('@medusajs/admin').PluginOptions} */
    options: {
      serve: true,
      autoRebuild: true,
      backend: MEDUSA_ADMIN_BACKEND_URL,
      outDir: 'build',
      develop: {
        open: process.env.OPEN_BROWSER !== 'false',
        logLevel: 'error',
        stats: 'normal',
      },
    },
  },
];

const modules = {
  eventBus: {
    resolve: '@medusajs/event-bus-redis',
    options: {
      redisUrl: REDIS_URL,
    },
  },
  cacheService: {
    resolve: '@medusajs/cache-redis',
    options: {
      redisUrl: process.env.CACHE_REDIS_URL,
      ttl: 30,
    },
  },
};

const projectConfig = {
  /** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */
  http_compression: {
    enabled: true,
    level: 6,
    memLevel: 8,
    threshold: 1024,
  },

  worker_mode: 'shared',

  jwtSecret: process.env.JWT_SECRET,
  cookieSecret: process.env.COOKIE_SECRET,
  store_cors: STORE_CORS,
  database_url: DATABASE_URL,
  admin_cors: ADMIN_CORS,
  redis_url: REDIS_URL,
};

/** @type {import('@medusajs/medusa').ConfigModule} */
module.exports = {
  projectConfig,
  plugins,
  modules,
  featureFlags: {
    // product_categories: true,
  },
};
amit5420 commented 2 months ago

@n3cr0murl0c did you get any solution for it

amit5420 commented 2 months ago

@shahednasser can you please help us out in this, as the new custom routes on the admin side is not visible on the live vercel server

n3cr0murl0c commented 2 months ago

@n3cr0murl0c did you get any solution for it

havent found a solution for the bug per se, but have found a workaround. I've generated another project from scratch, restructured again all my source files, configured everything again. So im guessing the problem is somewhere in the compiler options. But the problem of the repo to recreate the bug posted here still persits

github-actions[bot] commented 4 weeks ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 3 days.

KareemAbbas1 commented 3 weeks ago

Have anyone found a solution for this problem? It's weird! My project had many admin custom routes and widgets and everything was working fine, but suddenly out of no where all the custom routes and widgets are not displayed any more!

n3cr0murl0c commented 3 weeks ago

Have anyone found a solution for this problem? It's weird! My project had many admin custom routes and widgets and everything was working fine, but suddenly out of no where all the custom routes and widgets are not displayed any more!

the work around i found for this problem was creating a brand new blank project to load a new working (supposedly) configuration, then proceed to copy your customized routes/widgets. Haven't had the time to continue following the trace of the problem, as is it something with the compiler.

KareemAbbas1 commented 3 weeks ago

Have anyone found a solution for this problem? It's weird! My project had many admin custom routes and widgets and everything was working fine, but suddenly out of no where all the custom routes and widgets are not displayed any more!

the work around i found for this problem was creating a brand new blank project to load a new working (supposedly) configuration, then proceed to copy your customized routes/widgets. Haven't had the time to continue following the trace of the problem, as is it something with the compiler.

I followed a simillar approach to yours where I only deleted the admin directory and re-installed the admin plugin, and then re-created all the routes and widgets one by one.