cjs export is broken
- Importing this library and calling any of the function fails in node js.
For ex:
Both code snippets fails with error: encode is not a function
import bs58 from "bs58";
bs58.encode(...)
import * as bs58 from "bs58";
bs58.encode(...)
Import statements only work in esm modules (if you have "type": "module" in package.json). For CJS can you try this instead?
const bs58 = require("bs58").default;
bs58.encode(Buffer.from("test", "utf8"));
in typescript the error persists if using cjs and require pattern is not desired
@arijoon can you share minimal working reproduction? You can import CJS modules using ESM syntax
Sure I'll make a repo later in the week with reproduction. Using "typescript": "5.6.3",, the following error persists when importing bs58 with import bs58 from 'bs58':
The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("bs58")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/code/rhino-core/packages/dvf-bridge-api-spec/package.json'.
For now I've reverted to v5 which does not have this issue
What is the NodeJS version?
Are you using external tools like bun or deno or something?
Even though bs58 is marked as an ESM, it contains the require exports for CJS inside package.json... so something in your build pipeline is so old that it can't comprehend the exports key of package.json...
We can look into this when you give us a small repository to try it out with.
Repository to reproduce the issue: https://github.com/arijoon/bs58-53
@Nesopie Said he'll work on it. re: https://github.com/microsoft/TypeScript/issues/50466
Thanks, there's also a module-sync available with more recent versions of node, we're patching some of our deps to add this and it gets rid of the dual package issue at least on node https://nodejs.org/en/blog/release/v22.10.0
@arijoon Please review #56 and see if it fixes the issue.