readmeio / oas

Comprehensive tooling for working with OpenAPI definitions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for ESM

stijnvanhulle opened this issue · comments

Problem

Right now the package.json only contains main and types. That works most of the time fine but when using native ESM it will complain because inside the dist/index.js there is a require which is not supported by ESM.

Solution

  • Add "type": "module"
  • Add native ESM bundle
  • Add exports with support for CJS(as today) and ESM
 "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js", //esm
      "module": "./dist/index.js", //esm
      "default": "./dist/index.cjs" //cjs
    }
  },

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-move-my-commonjs-project-to-esm

Hi, we don't have any plans to natively support ESM at the moment but if you'd like to submit a PR to this repo to get it working to where the library could still be used in a CJS project, even with type: module present, we're open to pulling it in.