Getting error while using "mira-dex-ts" SDK

I am getting an error when using “mira-dex-ts” sdk in my NodeJs project -

Error: Directory import 'C:\Users\HP\Desktop\Trading-BOT\node_modules\mira-dex-ts\dist\sdk' is not supported resolving ES modules imported from C:\Users\HP\Desktop\Trading-BOT\node_modules\mira-dex-ts\dist\index.js
    at finalizeResolution (node:internal/modules/esm/resolve:263:11)
    at moduleResolve (node:internal/modules/esm/resolve:860:10)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:654:12)
    at ModuleLoader.#cachedDefaultResolve (node:internal/modules/esm/loader:603:25)
    at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:353:53)
    at new ModuleJobSync (node:internal/modules/esm/module_job:341:34)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:326:11)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1376:24)
    at Module.<anonymous> (node:internal/modules/cjs/loader:1528:5)
(node:19640) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
[ERROR] 01:00:19 Error: Directory import 'C:\Users\HP\Desktop\Trading-BOT\node_modules\mira-dex-ts\dist\sdk' is not supported resolving ES modules imported from C:\Users\HP\Desktop\Trading-BOT\node_modules\mira-dex-ts\dist\index.js
(node:19640) ExperimentalWarning: CommonJS module C:\Users\HP\Desktop\Trading-BOT\src\services\swap.ts is loading ES Module C:\Users\HP\Desktop\Trading-BOT\node_modules\mira-dex-ts\dist\index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time

This is how I am importing classes and methods from “mira-dex-ts” SDK -

import { buildPoolId, MiraAmm } from "mira-dex-ts";
...

This is my tsconfig.json file -

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "CommonJS",
    "outDir": "dist",
    "esModuleInterop": true,
    "strict": true,
    "moduleResolution": "node",
    "allowJs": true,
    "checkJs": false
  },
  "include": ["*.ts"]
}

This is my package.json file -

{
  "name": "...",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "ts-node index.ts",
    "build": "tsc",
    "dev": "ts-node-dev index.ts"
  },
  "dependencies": {
    ...
    "fuels": "^0.96.1",
    ...
    "mira-dex-ts": "^1.0.42",
    ...
  },
  "devDependencies": {
    ...
    "@types/express": "^4.17.15",
    "@types/node": "^20.17.11",
    "ts-node": "^10.9.2",
    "ts-node-dev": "^2.0.0",
    "typescript": "^5.7.2"
  }
}
2 Likes

Hey @bobby-lync :waving_hand:

Sorry about this, there appears to be an issue with how we’re bundling the SDK. The SDK source is ESM-only, however, the package.json suggests otherwise. I’m looking at pushing some changes to the SDK now, however, this will take some time to publish.


In the meantime, can I suggest using tsx:

pnpm install -D tsx

Then you should be able run your TS file as follows

"scripts": {
 "start": "tsx index.ts"
}