Skip to content

fix(core): explicit ESM specifiers so plain-Node ESM can import @sundaeswap/core#160

Open
rasheedja wants to merge 1 commit into
SundaeSwap-finance:mainfrom
rasheedja:fix/esm-directory-imports
Open

fix(core): explicit ESM specifiers so plain-Node ESM can import @sundaeswap/core#160
rasheedja wants to merge 1 commit into
SundaeSwap-finance:mainfrom
rasheedja:fix/esm-directory-imports

Conversation

@rasheedja

Copy link
Copy Markdown

Importing @sundaeswap/core under plain Node ESM ("type": "module", no bundler) currently fails:

node -e "import('@sundaeswap/core')"
# Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '…/dist/esm/@types' is not supported
# resolving ES modules imported from …/dist/esm/Configs/StrategyConfig.class.js

Cause: the ESM build emits import specifiers verbatim, and Node's ESM resolver does no directory resolution or extension guessing. Two files use directory/extensionless relative imports, while the rest of the package consistently writes explicit /index.js / .js specifiers:

  • Configs/StrategyConfig.class.tsfrom "../@types". This breaks the main entry: dist/esm/exports/core.js transitively loads StrategyConfig.class.js, so any plain-Node ESM import of the package throws.
  • TestUtilities/mocks.tsfrom "../exports/core". Same class of issue, latent on the ./testing entry (ERR_MODULE_NOT_FOUND).

CJS, Bun, and bundlers all do their own directory/extension resolution, which is why this has gone unnoticed.

Fix: make both specifiers explicit, matching the existing style everywhere else in the package (e.g. SundaeSDK.class.ts, Configs/SwapConfig.class.ts). No behavior change for any currently-working consumer.

Left to maintainers: version bump/changeset as you prefer, and optionally "moduleResolution": "node16"/"nodenext" in the core tsconfig would make tsc catch this class of specifier at build time.

Found while integrating @sundaeswap/core downstream in RealFi's partner SDK, where plain-Node ESM is currently documented as a known-broken runtime because of this.

🤖 Generated with Claude Code

Plain-Node ESM consumers fail with ERR_UNSUPPORTED_DIR_IMPORT: the ESM build emits import specifiers verbatim, and Node's ESM resolver does no directory or extension resolution. StrategyConfig.class.ts is loaded transitively by the main entry, so any 'type: module' import of @sundaeswap/core throws; mocks.ts is the same class of issue on the ./testing entry. Matches the explicit /index.js style used everywhere else in the package.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 6, 2026 14:56
@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5aea0c8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes plain-Node ESM compatibility for @sundaeswap/core by making two relative import specifiers explicit (no directory imports, no extensionless imports), aligning with the package’s existing ESM import style so Node’s ESM resolver can load the built dist/esm output correctly.

Changes:

  • Update StrategyConfig.class.ts to import types via ../@types/index.js instead of the directory ../@types.
  • Update TestUtilities/mocks.ts to import core exports via ../exports/core.js instead of the extensionless ../exports/core.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/core/src/TestUtilities/mocks.ts Makes the relative import specifier explicit (core.js) to avoid Node ESM extension guessing.
packages/core/src/Configs/StrategyConfig.class.ts Replaces a directory import with an explicit index.js specifier to prevent ERR_UNSUPPORTED_DIR_IMPORT in Node ESM.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rasheedja

Copy link
Copy Markdown
Author

Local verification (fork PRs won't run CI until approved, so ran the toolchain locally):

  • Build: build:esm + build:cjs compile clean on the patched source (the types/typecheck scripts fail identically on unpatched main — pre-existing emitDeclarationOnly+noEmit tsconfig conflict and unbuilt workspace @sundaeswap/math — unrelated to this change).
  • The fix, end-to-end: with the patched build, import('@sundaeswap/core') from a plain-Node "type": "module" package now resolves — previously ERR_UNSUPPORTED_DIR_IMPORT. (The ./testing entry additionally imports bun:test, so it remains bun-only by design; its specifier is corrected all the same.)
  • Tests: bun test Configs — 53 pass, 0 fail (includes StrategyConfig.class.test.ts, which exercises the patched import).

@rasheedja

rasheedja commented Jul 7, 2026

Copy link
Copy Markdown
Author

Companion fix for the next failure in the same Node-ESM chain: after these import specifiers are fixed, plain-Node ESM consumers hit @sundaeswap/math's missing module-type marker — two-line build fix in #161. The two are independent and mergeable in either order.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants