From a1ab11e3d9bcc065bb0f5cb1c307d295aef85505 Mon Sep 17 00:00:00 2001 From: wolfy1339 <4595477+wolfy1339@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:01:00 -0400 Subject: [PATCH] fix(pkg): add `default` fallback and `types` export (#419) * fix(pkg): add a default fallback See octokit/core.js#665 octokit/core.js#667 * docs: add note on needed config changes for TypeScript --- README.md | 6 ++++++ scripts/build.mjs | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c13d7b..6df9e36 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,12 @@ import { RequestError } from "@octokit/request-error"; +> [!IMPORTANT] +> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json` by setting `"moduleResolution": "node16", "module": "node16"`. +> +> See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).
+> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus) + ```js const error = new RequestError("Oops", 500, { request: { diff --git a/scripts/build.mjs b/scripts/build.mjs index 8c0cea3..2e6f4e0 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -50,12 +50,13 @@ async function main() { { ...pkg, files: ["dist-*/**", "bin/**"], - main: "./dist-src/index.js", types: "./dist-types/index.d.ts", exports: { ".": { types: "./dist-types/index.d.ts", import: "./dist-src/index.js", + // Tooling currently are having issues with the "exports" field when there is no "default", ex: TypeScript, eslint + default: "./dist-src/index.js", } }, sideEffects: false,