hashgraph / hashgraph/stablecoin-studio
ESM build is broken, cannot import `@hashgraph/stablecoin-npm-sdk` in Node.js ESM
- Dominant language
- TypeScript
- Stars
- 67
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
I would like to use stablecoin studio sdk in my plugin but because of problems with ESM imports I have errors. `@hashgraph/stablecoin-npm-sdk@4.2.0` cannot be imported in any Node.js ESM project (`"type": "module"`). The ESM build output (`build/esm/`) has three categories of bugs that prevent it from loading.
## Environment
- `@hashgraph/stablecoin-npm-sdk`: 4.2.0
- Node.js: v24.14.1 (also reproducible on v20+)
## Minimal reproduction
```bash
mkdir repro && cd repro
echo '{ "type": "module", "dependencies": { "@hashgraph/stablecoin-npm-sdk": "^4.2.0" } }' > package.json
npm install
node -e "import('@hashgraph/stablecoin-npm-sdk').then(m => console.log(Object.keys(m)))"
```
## Issue 1: Missing `.js` extensions in relative imports (162 occurrences)
Node.js ESM requires file extensions in relative import specifiers ([Node.js docs](https://nodejs.org/api/esm.html#mandatory-file-extensions)).
**Entry point** — `build/esm/src/index.js:23`:
```js
// ❌ Actual (missing .js extension)
export * from './port/in/index';
// ✅ Expected
export * from './port/in/index.js';
```
**Error:**
```
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../build/esm/src/port/in/index'
imported from .../build/esm/src/index.js
```
## Issue 2: `require()` used inside ESM file
**File:** `build/esm/src/port/out/hs/walletconnect/HederaWalletConnectTransactionAdapter.js:52`
```js
// ❌ require() is not available in ESM scope
const { SupportedWallets } = require('@hashgraph/stablecoin-npm-sdk');
```
**Error:**
```
ReferenceError: require is not defined in ES module scope, you can use import instead
```
This is also a circular self-import (the SDK requiring itself). It should use a regular ESM import:
```js
// ✅ Expected
import { SupportedWallets } from '@hashgraph/stablecoin-npm-sdk';
```
Same file also has dynamic `require()` calls at lines 56-58:
```js
const hwc = require('@hashgraph/hedera-wallet-connect');
const appkit = require('@reown/appkit');
```
These should use dynamic `import()` instead.
## Issue 3: Directory import through package `exports` wildcard
**File:** `build/esm/src/app/service/TransactionService.js:42`
```js
// ❌ Directory import — not supported through exports field
import * as Factories from '@hashgraph/stablecoin-npm-contracts/typechain-types/factories/contracts';
```
**`@hashgraph/stablecoin-npm-contracts/package.json` exports map:**
```json
{
"exports": {
"./typechain-types/*": {
"import": "./build/typechain-types/*",
"require": "./build/typechain-types/*"
}
}
}
```
**Error:**
```
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '.../factories/contracts' is not supported
resolving ES modules
```
The wildcard `*` in exports does not match directory paths. The import should include the explicit file:
```js
// ✅ Expected
import * as Factories from '@hashgraph/stablecoin-npm-contracts/typechain-types/factories/contracts/index.js';
```
**Note:** This issue also exists in the CJS build (`build/cjs/src/app/service/TransactionService.js:81`).
## Impact
- Any ESM project (`"type": "module"` in package.json) cannot use `@hashgraph/stablecoin-npm-sdk`
- This affects all modern Node.js projects using ESM, Next.js apps, and any bundler that relies on Node.js ESM resolution
- The CJS build (`build/cjs/`) works correctly (except for Issue 3)
**Additional**: `@hashgraph/stablecoin-npm-contracts` has simillar issues.
Contributor guide
Assessment
This issue has not been assessed yet.