Patch to make @octokit/types work with vite/astro

Github Mascot Octocat

Photograph by Roman Synkevych on Unsplash

If you are using node, use patch-package. If you are using pnpm use the in-built patch command.

Trying to use @octokit/types with vite/astro? You might run into this kind of error

This is because of how vite.js resolves packages. @octokit/types doesn't export any javascript file, so vite says

I don't recognise you, can't let you in.

You need to add a dummy main file in the package's package.json to make it happy. This is how patched package.json of @octokit/types should look like

diff --git a/index.js b/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/package.json b/package.json
index 7ee12d257f4213c3583c11acbfde95895f80d261..2693b41cab2f0865f76de2bff5e600a114ccf6e4 100644
--- a/package.json
+++ b/package.json
@@ -43,5 +43,13 @@
     "dist-types/**"
   ],
   "types": "dist-types/index.d.ts",
+  "exports": {
+    ".": {
+      "import": "./index.js",
+      "require": "./index.js",
+      "types": "./dist-types/index.d.ts"
+    }
+  },
+  "main": "./index.js",
   "sideEffects": false
 }

If this helped you down, consider giving me a shout out on twitter :)


If you enjoyed this article please consider subscribing to my tech newsletter.