sharkdp / insect

High precision scientific calculator with support for physical units
https://numbat.dev/
MIT License
3.17k stars 126 forks source link

Fix running `index.cjs` and check that it works successfully in CI #357

Closed triallax closed 1 year ago

triallax commented 1 year ago

Some change in decimal.js 10.4.0 (almost certainly https://github.com/MikeMcl/decimal.js/commit/0bc3fdbdaa5e8d2f58087a8fceb200da28fa6d5c) broke running index.cjs. Previously, the CommonJS decimal.js module was imported, but with decimal.js 10.4.0 decimal.mjs is instead imported, thus the following error when running index.cjs:

node:internal/modules/cjs/loader:1041
    throw new ERR_REQUIRE_ESM(filename, true);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/triallax/Desktop/insect/node_modules/decimal.js/decimal.mjs not supported.
Instead change the require of /home/triallax/Desktop/insect/node_modules/decimal.js/decimal.mjs to a dynamic import() which is available in all CommonJS modules.
    at /home/triallax/Desktop/insect/index.cjs:4:42947
    at Object.<anonymous> (/home/triallax/Desktop/insect/index.cjs:15:331) {
  code: 'ERR_REQUIRE_ESM'
}

This PR also adds a step in the CI that runs ./index.cjs, to ensure a situation like this doesn't happen again in the future.