break_eternity.js icon indicating copy to clipboard operation
break_eternity.js copied to clipboard

Typescript CommonJS not exported properly

Open HcgRandon opened this issue 3 years ago • 2 comments

When trying to import this lib from a nodejs typescript project in module: commonjs mode it is unusable.

I Import via import Decimal from 'break_eternity.js';.

Any call to new Decimal(); results in TypeError: break_eternity_js_1.default is not a constructor. I have some experience with these issues myself and will attempt to debug when I have time, but thought I should track it here sooner then later

HcgRandon avatar Oct 16 '22 22:10 HcgRandon

Thanks, I'm not very strong at Typescript so I appreciate the help if you get time for it.

Patashu avatar Oct 16 '22 22:10 Patashu

The bili lib I originally set up for TS looks to have been abandoned, and we have esbuild that can do all of the things now. Might be worth switching over to it.

@HcgRandon it's been a while but if you're still using this lib, could you try it with esbuild?

// esbuild.ts
import esbuild, { BuildOptions } from "esbuild";

const options: BuildOptions = {
  entryPoints: ["src/index.ts"],
  outdir: "lib",
  bundle: true,
  sourcemap: true,
  logLevel: "info"
}

// cjs
esbuild
  .build({
    ...options,
    platform: "node",
    outExtension: { ".js": ".cjs.js" },
    target: ["node10.4"],
  })
  .catch(() => process.exit(1));

And then run with

$ npx ts-node esbuild.ts

bbugh avatar Feb 28 '23 04:02 bbugh