medusajs/medusa

[@medusajs/js-sdk] Vite SSR fails on extensionless rbac-role import in 2.15.5

Closed

#15,596 opened on Jun 4, 2026

 (1 comment) (0 reactions) (0 assignees)TypeScript (2,090 forks)batch import
good first issuetype: bug

Repository metrics

Stars
 (22,539 stars)
PR merge metrics
 (Avg merge 10d 22h) (185 merged PRs in 30d)

Description

Bug report

Describe the bug

In a Vite SSR storefront using the root @medusajs/js-sdk client import, dev SSR fails when Vite/TanStack Start externalizes @medusajs/js-sdk and Node tries to execute the package ESM directly.

This looks related to the ESM packaging issue previously tracked in medusajs/medusa#9573 and addressed by #15037, but @medusajs/js-sdk@2.15.5 still appears to contain at least two extensionless relative imports in dist/esm/admin/index.js:

import { RbacRole } from "./rbac-role";
import { RbacPolicy } from "./rbac-policy";

Most nearby imports in the same file already use explicit .js extensions, for example:

import { ApiKey } from "./api-key.js";
import { Translation } from "./translation.js";

Node's ESM resolver does not resolve extensionless relative imports, so SSR fails if the dependency is externalized instead of bundled/transformed by Vite.

Error

Cannot find module '<project>/node_modules/.pnpm/@medusajs+js-sdk@2.15.5/node_modules/@medusajs/js-sdk/dist/esm/admin/rbac-role' imported from <project>/node_modules/.pnpm/@medusajs+js-sdk@2.15.5/node_modules/@medusajs/js-sdk/dist/esm/admin/index.js

System information

  • Package: @medusajs/js-sdk@2.15.5
  • App: Vite SSR / TanStack Start storefront
  • Package manager / repo shape: pnpm monorepo
  • Runtime behavior: the SDK is externalized during dev SSR, so Node executes the SDK's ESM output directly

Steps to reproduce the behavior

  1. Use @medusajs/js-sdk@2.15.5 from a Vite SSR app, such as a TanStack Start storefront.
  2. Import the SDK from the root package entrypoint, for example:
import Medusa from "@medusajs/js-sdk"
  1. Start the Vite/TanStack dev server with the SDK externalized for SSR.
  2. Node ESM fails to resolve the extensionless internal import from dist/esm/admin/index.js.

Expected behavior

The root Medusa SDK import should work in Vite SSR without consumers needing custom ssr.noExternal config or deep imports around the SDK package.

Actual behavior

Node ESM fails while resolving an extensionless internal SDK import when the dependency is externalized during SSR.

Workaround

Bundling the SDK through Vite fixes the dev SSR failure:

// vite.config.mts
export default defineConfig({
  ssr: {
    noExternal: ["@medusajs/js-sdk"],
  },
})

With this workaround, Vite/TanStack Start dev starts successfully and the rbac-role resolution error goes away.

Suggested resolution

Any of these would help:

  • publish the ESM build with explicit .js extensions for these remaining relative imports, including ./rbac-role.js and ./rbac-policy.js;
  • document the Vite SSR / TanStack Start workaround using ssr.noExternal: ["@medusajs/js-sdk"];
  • or otherwise make the SDK's root import work cleanly when used from Vite SSR and executed by Node's ESM loader.

Thanks.

Contributor guide