GoogleChromeLabs / jsbi

JSBI is a pure-JavaScript implementation of the official ECMAScript BigInt proposal.

Home Page:https://v8.dev/features/bigint#polyfilling-transpiling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CJS Module will not work on browser due to different JSBI's build target

thanpolas opened this issue · comments

JSBI has different builds depending on the environment:

  "main": "dist/jsbi-cjs.js",
  "module": "dist/jsbi.mjs",
  "browser": "dist/jsbi-umd.js",

when the "module" or "browser" targets are used the CJS modules that depend on JSBI will break with an error of JSBI.BigInt is not a Function.

What would you advise so that a CJS library can safely work with JSBI in all environments?

Believe there is relation to issue #42, which also happens to be the answer to life the universe and everything

image

yea, as I suspected, the BigInt function on the jsbi-umd module can be found on the path jsbi.default.BigInt.

I will work around that on my library to do heuristics and figure out where to find the expected functions from the JSBI package as I don't expect this to be resolved.

It's interesting where we've come with Javascript and interoperability between packages.

I think this probably needs to be fixed similar to #69 - specifically,

exports: 'named',
needs to be set to "default", not "named".

I'll send a PR if I can validate this will actually fix your issue.