richardscarrott / ok-computer

λ "Functions all the way down" data validation for JavaScript and TypeScript.
MIT License
79 stars 0 forks source link

ESM module export not used by node #6

Open richardscarrott opened 2 years ago

richardscarrott commented 2 years ago

Think it a) needs "exports" and b) needs .mjs extension, that way older versions can continue to load the cjs version.

e.g.

"module": "dist/ok-computer.esm.mjs",
  "types": "dist/ok-computer.d.ts",
  "exports": {
    ".": {
      "import": "./dist/ok-computer.esm.mjs",
      "require": "./dist/ok-computer.esm.mjs",
      "types": "./dist/ok-computer.d.ts"
    }
  },

Not sure if it's ok to have "module" with an mjs path?

richardscarrott commented 2 years ago

Additionally, current master has this

import * as parser from "ok-computer/dist/cjs/parser";

Instead of

import * as p from "ok-computer/parser";
unsaved commented 1 year ago

This Issue is still open but I'm able to successfully load ok-computer from Node CommonJS require; from Node ES6 import...from; and from Deno. What is the case that isn't supported?

richardscarrott commented 1 year ago

All environments are supported, however the ESM build isn't being used by Node as I had expected. It instead was pulling in the CJS build. Not really a big deal but a bug nonetheless.