From 4cb8fbece37adfe7f504c4a8482f9110c8bbcd60 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Mon, 6 Nov 2023 16:25:25 +0800 Subject: [PATCH] fix: change the order of `exports` field keys to fix type resolution As both `./min` and `.` points to the same type definition file, sometimes TypeScript will resolve the type definition file to the `./min` key as it appears first. https://github.com/microsoft/TypeScript/issues/56290#issuecomment-1792883895 While this is not incorrect behavior, it breaks compatibility with older build environments that do not support the `exports` field. (e.g. TypeScript with `moduleResolution: "node"` instead of `bundler` or `node16`), as the `./min` entry is only available through the `exports` field. Some Vue.js users are experiencing this issue: https://github.com/vuejs/core/issues/9521 --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bae4a04..aff72fe 100644 --- a/package.json +++ b/package.json @@ -32,24 +32,24 @@ "main": "./dist/cjs/index.js", "module": "./dist/mjs/index.js", "exports": { - "./min": { + ".": { "import": { "types": "./dist/mjs/index.d.ts", - "default": "./dist/mjs/index.min.js" + "default": "./dist/mjs/index.js" }, "require": { "types": "./dist/cjs/index.d.ts", - "default": "./dist/cjs/index.min.js" + "default": "./dist/cjs/index.js" } }, - ".": { + "./min": { "import": { "types": "./dist/mjs/index.d.ts", - "default": "./dist/mjs/index.js" + "default": "./dist/mjs/index.min.js" }, "require": { "types": "./dist/cjs/index.d.ts", - "default": "./dist/cjs/index.js" + "default": "./dist/cjs/index.min.js" } } },