fix(js-sdk): add explicit .js extensions to relative imports for ESM compliance#15037
fix(js-sdk): add explicit .js extensions to relative imports for ESM compliance#15037pevey wants to merge 2 commits intomedusajs:developfrom
Conversation
…compliance The compiled ESM output contained bare directory imports (e.g., `export from './admin'`) which fail under Node.js native ESM resolution used by SvelteKit and Astro during SSR. Adding explicit `.js` extensions ensures the ESM output is spec-compliant while remaining backwards-compatible with CJS and bundler consumers. Fixes medusajs#9573 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
🦋 Changeset detectedLatest commit: a9fa38c The changes in this PR will be included in the next version bump. This PR includes changesets to release 77 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@pevey is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
|
Thank you for your contribution! After reviewing this PR, we need a few things addressed before we can move forward: Required changes:
Once these are addressed, another review will be triggered automatically. Thanks! |
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
A note on the direction of the PR: Strict ESM compliance in the compiled output could also be accomplished by only touching the tsconfig, which would seem to be a smaller change. But after trial and error with lots of different settings (with the help of Claude), I couldn't find a way of taking that approach that ALSO preserved cjs compatibility. That was the reason for this approach. I wanted to make sure the change did not cause any loss of current compatibility. If cjs compatibility is no longer a concern, a tsconfig change would be cleaner. |
Fixes #9573
Summary
.jsextensions to all relative imports in@medusajs/js-sdksource filesRoot Cause
The ESM build output (
dist/esm/) contained bare directory imports likeexport from './admin'and extensionless file imports likeimport from './client'. These work in bundlers but fail under Node.js native ESM, which strictly requires explicit paths (./admin/index.js,./client.js).Frameworks like SvelteKit and Astro use Node's native ESM loader for SSR, causing runtime import resolution errors.
Test plan
yarn workspace @medusajs/js-sdk test— all 20 tests passyarn workspace @medusajs/js-sdk build— builds successfullydist/esm/index.jsoutput contains proper.jsextensionsrequire()still worksimportworks under Node.js native ESMNote
Low Risk
Low risk: this is a mechanical import-path change to improve Node native ESM resolution, with no runtime logic changes. Main risk is accidental missed/incorrect paths causing module-resolution failures in some build targets.
Overview
Fixes Node native ESM/SSR consumption of
@medusajs/js-sdkby making all internal relative imports explicitly include.js(and using./*/index.jswhere applicable).Updates the public entry (
src/index.ts),client.ts, and the admin/auth/store modules to use ESM-compliant import specifiers, and adds a patch changeset for the release.Reviewed by Cursor Bugbot for commit a9fa38c. Bugbot is set up for automated code reviews on this repo. Configure here.