medusa icon indicating copy to clipboard operation
medusa copied to clipboard

[Bug]: A new "admin" exports in the package.json broken plugin development

Open kriss145 opened this issue 5 months ago • 4 comments

Package.json file

{
  "name": "@team/plugin",
  "version": "0.0.6",
  "description": "A starter for Medusa plugins.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "publishConfig": {
    "access": "restricted"
  },  
  "files": [
    ".medusa/server"
  ],
  "exports": {
    "./package.json": "./package.json",
    "./workflows": "./.medusa/server/src/workflows/index.js",
    "./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
    "./modules/*": "./.medusa/server/src/modules/*/index.js",
    "./providers/*": "./.medusa/server/src/providers/*/index.js",
    "./*": "./.medusa/server/src/*.js",
    "./admin": {
      "import": "./.medusa/server/src/admin/index.mjs",
      "require": "./.medusa/server/src/admin/index.js",
      "default": "./.medusa/server/src/admin/index.js"
    }
  },
  "keywords": [
    "medusa",
    "plugin",
    "medusa-plugin-other",
    "medusa-plugin",
    "medusa-v2"
  ],
  "scripts": {
    "build": "medusa plugin:build",
    "dev": "medusa plugin:develop",
    "prepublishOnly": "medusa plugin:build"
  },
  "devDependencies": {
    "@medusajs/admin-sdk": "2.7.1",
    "@medusajs/cli": "2.7.1",
    "@medusajs/framework": "2.7.1",
    "@medusajs/icons": "2.7.1",
    "@medusajs/medusa": "2.7.1",
    "@medusajs/test-utils": "2.7.1",
    "@medusajs/ui": "4.0.4",
    "@mikro-orm/cli": "6.4.3",
    "@mikro-orm/core": "6.4.3",
    "@mikro-orm/knex": "6.4.3",
    "@mikro-orm/migrations": "6.4.3",
    "@mikro-orm/postgresql": "6.4.3",
    "@swc/core": "1.5.7",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "awilix": "^8.0.1",
    "pg": "^8.13.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",
    "yalc": "^1.0.0-pre.53"
  },
  "peerDependencies": {
    "@medusajs/admin-sdk": "2.7.1",
    "@medusajs/cli": "2.7.1",
    "@medusajs/framework": "2.7.1",
    "@medusajs/icons": "2.7.1",
    "@medusajs/medusa": "2.7.1",
    "@medusajs/test-utils": "2.7.1",
    "@medusajs/ui": "4.0.3",
    "@mikro-orm/cli": "6.4.3",
    "@mikro-orm/core": "6.4.3",
    "@mikro-orm/knex": "6.4.3",
    "@mikro-orm/migrations": "6.4.3",
    "@mikro-orm/postgresql": "6.4.3",
    "awilix": "^8.0.1",
    "pg": "^8.13.0"
  },
  "engines": {
    "node": ">=20"
  },
  "dependencies": {
    "firebase-admin": "^13.4.0",
    "mqtt": "^5.13.0"
  }
}

Node.js version

22.10.0

Database and its version

PostgreSQL 16

Operating system name and version

MacOS 15.3.2

Browser name

Google Chrome

What happended?

When a new "exports" lines for "admin" are added in the package.json of the plugin, development process is broken. When I'm changing something in the "admin" routes, nothing happens, but when I change something in the "loaders" the refresh works and the back-end is rebuilt again. Unfortunately, with an error (like below). Without these lines a production version don't work good and "admin" routes are not visible / don't work.

13:24:23 [vite] error while updating dependencies:
Error: ENOENT: no such file or directory, open '//node_modules/@team/plugin/.medusa/server/src/admin/index.mjs'
    at async open (node:internal/fs/promises:638:25)
    at async Object.readFile (node:internal/fs/promises:1238:14)
    at async extractExportsData (file:///node_modules/vite/dist/node/chunks/dep-C6uTJdX2.js:51156:24)
    at async file:///node_modules/vite/dist/node/chunks/dep-C6uTJdX2.js:50904:27
    at async Promise.all (index 10)
    at async prepareEsbuildOptimizerRun (file:///node_modules/vite/dist/node/chunks/dep-C6uTJdX2.js:50901:3)

Expected behavior

Admin routes should work during the development process and production version.

Actual behavior

Admin routes during development don't work as well when a new lines in the package.json are added.

Link to reproduction repo

I have not repository :(

kriss145 avatar May 21 '25 12:05 kriss145