Patashu / break_eternity.js

A Javascript numerical library to represent numbers as large as 10^^1e308 and as small as 10^-10^^1e308. Sequel to break_infinity.js, designed for incremental games.
MIT License
120 stars 43 forks source link

Typescript CommonJS not exported properly #131

Open HcgRandon opened 1 year ago

HcgRandon commented 1 year ago

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

Patashu commented 1 year ago

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

bbugh commented 1 year ago

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