{"id":15413438,"url":"https://github.com/wooorm/package-exports","last_synced_at":"2025-04-15T22:51:29.627Z","repository":{"id":208435246,"uuid":"721650827","full_name":"wooorm/package-exports","owner":"wooorm","description":"Get the exports of a package","archived":false,"fork":false,"pushed_at":"2024-04-23T14:00:48.000Z","size":43,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T02:12:18.004Z","etag":null,"topics":["api","conditions","exports","node","npm","package"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":"funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"wooorm"}},"created_at":"2023-11-21T13:51:57.000Z","updated_at":"2024-09-29T18:12:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"67480a6d-d2a9-40eb-8bb6-936e1514968f","html_url":"https://github.com/wooorm/package-exports","commit_stats":null,"previous_names":["wooorm/package-exports"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fpackage-exports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fpackage-exports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fpackage-exports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fpackage-exports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/package-exports/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830395,"owners_count":21168272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","conditions","exports","node","npm","package"],"created_at":"2024-10-01T16:57:04.706Z","updated_at":"2025-04-15T22:51:29.609Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/wooorm"],"categories":[],"sub_categories":[],"readme":"# package-exports\n\n[![Build][badge-build-image]][badge-build-url]\n[![Coverage][badge-coverage-image]][badge-coverage-url]\n[![Downloads][badge-downloads-image]][badge-downloads-url]\n\nGet the exports of a package.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`packageExports(folder)`](#packageexportsfolder)\n  * [`Export`](#export)\n  * [`Result`](#result)\n* [Errors](#errors)\n  * [`exports-alternatives`](#exports-alternatives)\n  * [`exports-alternatives-empty`](#exports-alternatives-empty)\n  * [`exports-conditions-default-misplaced`](#exports-conditions-default-misplaced)\n  * [`exports-conditions-default-missing`](#exports-conditions-default-missing)\n  * [`exports-conditions-mutually-exclusive`](#exports-conditions-mutually-exclusive)\n  * [`exports-conditions-verbose`](#exports-conditions-verbose)\n  * [`exports-main-missing`](#exports-main-missing)\n  * [`exports-negated-missing`](#exports-negated-missing)\n  * [`exports-object-empty`](#exports-object-empty)\n  * [`exports-object-mixed`](#exports-object-mixed)\n  * [`exports-path-not-found`](#exports-path-not-found)\n  * [`exports-path-unprefixed`](#exports-path-unprefixed)\n  * [`exports-path-wildcard-not-found`](#exports-path-wildcard-not-found)\n  * [`exports-specifier-extension`](#exports-specifier-extension)\n  * [`exports-specifier-nested`](#exports-specifier-nested)\n  * [`exports-specifier-wildcard-invalid`](#exports-specifier-wildcard-invalid)\n  * [`exports-specifier-wildcard-useless`](#exports-specifier-wildcard-useless)\n  * [`exports-specifiers-verbose`](#exports-specifiers-verbose)\n  * [`exports-types-verbose`](#exports-types-verbose)\n  * [`exports-value-invalid`](#exports-value-invalid)\n  * [`files-missing`](#files-missing)\n  * [`main`](#main)\n  * [`main-extra`](#main-extra)\n  * [`main-inferred`](#main-inferred)\n  * [`main-invalid`](#main-invalid)\n  * [`main-missing`](#main-missing)\n  * [`main-not-found`](#main-not-found)\n  * [`main-resolve-commonjs`](#main-resolve-commonjs)\n  * [`main-resolve-module`](#main-resolve-module)\n  * [`name-missing`](#name-missing)\n  * [`npm-ignored`](#npm-ignored)\n  * [`type-invalid`](#type-invalid)\n  * [`type-missing`](#type-missing)\n* [Compatibility](#compatibility)\n* [Security](#security)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package finds out what is exposed from a package.\nIt also emits many possible warnings about potential problems.\n\n## When should I use this?\n\nYou can use this to programatically figure out what can be used from a package.\nYou can also use this to lint packages.\n\n## Install\n\nThis package is [ESM only][github-gist-esm].\nIn Node.js (version 18+), install with [npm][npm-install]:\n\n```sh\nnpm install package-exports\n```\n\n## Use\n\n```js\nimport {packageExports} from 'package-exports'\nimport {reporter} from 'vfile-reporter'\n\nconst thisPackage = await packageExports(new URL('.', import.meta.url))\n\nconsole.dir(thisPackage, {depth: undefined})\n\nconst tar = await packageExports(new URL('node_modules/tar/', import.meta.url))\nconsole.error(reporter(tar.file))\n```\n\nYields:\n\n```js\n{\n  exports: [\n    {\n      conditions: undefined,\n      exists: true,\n      jsonPath: [ 'exports' ],\n      specifier: '.',\n      url: 'file:///Users/…/package-exports/index.js'\n    }\n  ],\n  file: VFile { … },\n  name: 'package-exports'\n}\n```\n\n```txt\nnode_modules/tar/package.json\n1:1-70:2 warning Unexpected inferred main export `./index.js`, it’s recommended to use an export map such as `\"exports\": \"./index.js\"` main-inferred package-exports\n1:1-70:2 warning Unexpected missing `type` field, expected `type: 'commonjs'` or `'module'`                                            type-missing  package-exports\n\n⚠ 2 warnings\n```\n\n## API\n\nThis package exports the identifier\n[`packageExports`][api-package-exports].\nIt exports the [TypeScript][] types\n[`Export`][api-export] and\n[`Result`][api-result].\nThere is no default export.\n\n### `packageExports(folder)`\n\nGet the exports of a package.\n\n###### Parameters\n\n* `folder` (`URL`, required)\n  — file URL to folder of a package\n\n###### Returns\n\nResult ([`Promise\u003cResult\u003e`][api-result]).\n\n### `Export`\n\nExport (TypeScript type).\n\n###### Fields\n\n* `conditions` (`Array\u003cstring\u003e`)\n  — conditions\n* `exists` (`boolean`)\n  — whether this file exists\n* `jsonPath` (`Array\u003cnumber | string\u003e`)\n  — path in `package.json`\n* `specifier` (`string`)\n  — specifier that exposes this\n* `url` (`URL`)\n  — resolved URL to file\n\n### `Result`\n\nResult of finding exports (TypeScript type).\n\n###### Fields\n\n* `exports` ([`Array\u003cExports\u003e`][api-export])\n  — exports\n* `file` ([`VFile`][github-vfile])\n  – file\n* `name` (`string` or `undefined`)\n  – package name\n\n## Errors\n\nThis package lints for many problems in npm packages and adds each message to\nthe [vfile][github-vfile].\nMessages will have a `source` field set to `package-exports` and a `ruleId`\nto one of the following values.\n\n### `exports-alternatives`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./other\": [\n      \"./other.js\"\n    ]\n  },\n  \"files\": [\n    \"index.js\",\n    \"other.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:16-6:6: Unexpected alternatives list at `exports['./other']`, several tools don’t support this and pick the first item\n```\n\nFix:\n\n```diff\n@@ -1,7 +1,7 @@\n {\n   \"exports\": {\n     \".\": \"./index.js\",\n-    \"./other\": [\"./other.js\"]\n+    \"./other\": \"./other.js\"\n   },\n   \"files\": [\"index.js\", \"other.js\"],\n   \"name\": \"x\",\n```\n\n### `exports-alternatives-empty`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./other\": []\n  },\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:16-4:18: Unexpected empty array at `exports['./other']` doing nothing, expected a single item\n```\n\nFix:\n\n```diff\n@@ -1,7 +1,6 @@\n {\n   \"exports\": {\n-    \".\": \"./index.js\",\n-    \"./other\": []\n+    \".\": \"./index.js\"\n   },\n   \"files\": [\"index.js\"],\n   \"name\": \"x\",\n```\n\n### `exports-conditions-default-misplaced`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \"default\": \"./index.js\",\n    \"production\": \"./other.js\"\n  },\n  \"files\": [\n    \"index.js\",\n    \"other.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:19-4:31: Unexpected non-last `default` conditions at `exports` ignoring everything after it, move the `default` condition to the end\n```\n\nFix:\n\n```diff\n@@ -1,7 +1,7 @@\n {\n   \"exports\": {\n-    \"default\": \"./index.js\",\n-    \"production\": \"./other.js\"\n+    \"production\": \"./other.js\",\n+    \"default\": \"./index.js\"\n   },\n   \"files\": [\"index.js\", \"other.js\"],\n   \"name\": \"x\",\n```\n\n### `exports-conditions-default-missing`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \"production\": \"./index.js\"\n  },\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n2:14-4:4: Unexpected conditions without a `default` entry at `exports` making specifier `.` unusable by default, expected `'default'` condition as the last field\n```\n\nFix:\n\n```diff\n@@ -1,6 +1,7 @@\n {\n   \"exports\": {\n-    \"production\": \"./index.js\"\n+    \"production\": \"./index.js\",\n+    \"default\": \"./other.js\"\n   },\n   \"files\": [\n     \"index.js\"\n```\n\n### `exports-conditions-mutually-exclusive`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \"import\": {\n      \"require\": \"./other.js\",\n      \"default\": \"./index.js\"\n    },\n    \"default\": \"./index.js\"\n  },\n  \"files\": [\n    \"index.js\",\n    \"other.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:18-4:30: Unexpected condition `require` mutually exclusive with `import` at `exports.import` which never matches, use only one of these conditions\n```\n\nFix:\n\n```diff\n@@ -1,10 +1,7 @@\n {\n   \"exports\": {\n-    \"import\": {\n-      \"require\": \"./other.js\",\n-      \"default\": \"./index.js\"\n-    },\n-    \"default\": \"./index.js\"\n+    \"require\": \"./other.js\",\n+    \"import\": \"./index.js\"\n   },\n   \"files\": [\n     \"index.js\",\n```\n\n### `exports-conditions-verbose`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \"default\": \"./index.js\"\n  },\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n2:14-4:4: Unexpected verbose conditions object with sole key `default` at `exports`, replace the object with the value at `default`\n```\n\nFix:\n\n```diff\n@@ -1,7 +1,5 @@\n {\n-  \"exports\": {\n-    \"default\": \"./index.js\"\n-  },\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.js\"\n   ],\n```\n\n### `exports-main-missing`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \"./x\": \"./index.js\"\n  },\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n1:1-10:2: Unexpected missing main specifier `.`, expected an export to the main module\n```\n\nFix:\n\n```diff\n@@ -1,5 +1,6 @@\n {\n   \"exports\": {\n+    \".\": \"./index.js\",\n     \"./x\": \"./index.js\"\n   },\n   \"files\": [\n```\n\n### `exports-negated-missing`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./*\": null\n  },\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:12-4:16: Unexpected negation specifier `./*` at `exports['./*']` with nothing to negate\n```\n\nFix:\n\n```diff\n@@ -1,6 +1,7 @@\n {\n   \"exports\": {\n     \".\": \"./index.js\",\n+    \"./x\": \"./index.js\",\n     \"./*\": null\n   },\n   \"files\": [\n```\n\n### `exports-object-empty`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./other\": {}\n  },\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:16-4:18: Unexpected empty object at `exports['./other']` doing nothing, expected fields\n```\n\nFix:\n\n```diff\n@@ -1,7 +1,6 @@\n {\n   \"exports\": {\n-    \".\": \"./index.js\",\n-    \"./other\": {}\n+    \".\": \"./index.js\"\n   },\n   \"files\": [\n     \"index.js\"\n```\n\n### `exports-object-mixed`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"default\": \"./other.js\"\n  },\n  \"files\": [\n    \"index.js\",\n    \"other.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n1:1-12:2: Unexpected missing main specifier `.`, expected an export to the main module\n2:14-5:4: Unexpected mixed specifiers (starting with `.`) and conditions (without `.`) at `exports`, expected either specifiers or conditions\n```\n\nFix:\n\n```diff\n@@ -1,6 +1,6 @@\n {\n   \"exports\": {\n-    \".\": \"./index.js\",\n+    \"other\": \"./index.js\",\n     \"default\": \"./other.js\"\n   },\n   \"files\": [\n```\n\n### `exports-path-not-found`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./x\": \"./missing.js\"\n  },\n  \"files\": [\n    \"index.js\",\n    \"missing.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:12-4:26: Unexpected missing file `./missing.js` for specifier `./x` at `exports['./x']`\n```\n\nFix: make sure files exist.\n\n### `exports-path-unprefixed`\n\n`package.json`:\n\n```json\n{\n  \"exports\": \"index.js\",\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n1:1-8:2: Unexpected missing main specifier `.`, expected an export to the main module\n2:14-2:24: Unexpected unprefixed value `'index.js'` at `exports` which is not importable, did you mean `'./index.js'`\n```\n\nFix:\n\n```diff\n@@ -1,5 +1,5 @@\n {\n-  \"exports\": \"index.js\",\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.js\"\n   ],\n```\n\n### `exports-path-wildcard-not-found`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./*\": \"./lib/*\"\n  },\n  \"files\": [\n    \"lib/\",\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:12-4:21: Unexpected dynamic file glob `./lib/*` at `exports['./*']` pointing to nothing, expected files\n```\n\nFix: make sure files exist.\n\n### `exports-specifier-extension`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./other.js\": \"./other.js\"\n  },\n  \"files\": [\n    \"index.js\",\n    \"other.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n2:14-5:4: Unexpected extension `.js` in specifier `./other.js` at `exports`, extensions have no meaning in specifiers, expected `./other`\n```\n\nFix:\n\n```diff\n@@ -1,7 +1,7 @@\n {\n   \"exports\": {\n     \".\": \"./index.js\",\n-    \"./other.js\": \"./other.js\"\n+    \"./other\": \"./other.js\"\n   },\n   \"files\": [\n     \"index.js\",\n```\n\n### `exports-specifier-nested`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./other\": {\n      \"./more\": \"./other.js\"\n    }\n  },\n  \"files\": [\n    \"index.js\",\n    \"other.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:16-6:6: Unexpected nested specifier `./more` at `exports['./other']`, expected conditions\n```\n\nFix:\n\n```diff\n@@ -1,9 +1,7 @@\n {\n   \"exports\": {\n     \".\": \"./index.js\",\n-    \"./other\": {\n-      \"./more\": \"./other.js\"\n-    }\n+    \"./other/more\": \"./other.js\"\n   },\n   \"files\": [\n     \"index.js\",\n```\n\n### `exports-specifier-wildcard-invalid`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./x/*/y/*\": \"./other.js\"\n  },\n  \"files\": [\n    \"index.js\",\n    \"other.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:18-4:30: Unexpected extra wildcard in dynamic specifier `./x/*/y/*` at `exports['./x/*/y/*']`, one wildcard is allowed\n```\n\nFix:\n\n```diff\n@@ -1,7 +1,7 @@\n {\n   \"exports\": {\n     \".\": \"./index.js\",\n-    \"./x/*/y/*\": \"./other.js\"\n+    \"./x/*/y\": \"./other.js\"\n   },\n   \"files\": [\n     \"index.js\",\n```\n\n### `exports-specifier-wildcard-useless`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./*\": \"./other.js\"\n  },\n  \"files\": [\n    \"index.js\",\n    \"other.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:12-4:24: Unexpected dynamic specifier `./*` pointing to static file `./other.js` at `exports['./*']`, use dynamic specifiers with dynamic file globs\n```\n\nFix:\n\n```diff\n@@ -1,7 +1,7 @@\n {\n   \"exports\": {\n     \".\": \"./index.js\",\n-    \"./*\": \"./other.js\"\n+    \"./other\": \"./other.js\"\n   },\n   \"files\": [\n     \"index.js\",\n```\n\n### `exports-specifiers-verbose`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\"\n  },\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n2:14-4:4: Unexpected verbose specifier object with sole key `.` at `exports`, replace the object with the value at `.`\n```\n\nFix:\n\n```diff\n@@ -1,7 +1,5 @@\n {\n-  \"exports\": {\n-    \".\": \"./index.js\"\n-  },\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.js\"\n   ],\n```\n\n### `exports-types-verbose`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \"types\": \"./index.d.ts\",\n    \"default\": \"./index.js\"\n  },\n  \"files\": [\n    \"index.d.ts\",\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n3:14-3:28: Unexpected verbose `types` condition at `exports` matching what TypeScript would load for `default` without it, remove it\n```\n\nFix:\n\n```diff\n@@ -1,8 +1,5 @@\n {\n-  \"exports\": {\n-    \"types\": \"./index.d.ts\",\n-    \"default\": \"./index.js\"\n-  },\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.d.ts\",\n     \"index.js\"\n```\n\n### `exports-value-invalid`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./other\": 1\n  },\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:16-4:17: Unexpected invalid value `1` at `exports['./other']` which is not importable, expected conditions object, `string` (path to file), or `null` (negated)\n```\n\nFix:\n\n```diff\n+++ b/example/package.json\n@@ -1,7 +1,7 @@\n {\n   \"exports\": {\n     \".\": \"./index.js\",\n-    \"./other\": 1\n+    \"./other\": \"./other.js\"\n   },\n   \"files\": [\n     \"index.js\"\n```\n\n### `files-missing`\n\n`package.json`:\n\n```json\n{\n  \"exports\": \"./index.js\",\n  \"name\": \"x\",\n  \"type\": \"module\",\n}\n```\n\nYields:\n\n```txt\n1:1-5:2: Unexpected missing `files` field, expected array of allowed files to include\n```\n\nFix:\n\n```diff\n@@ -1,5 +1,8 @@\n {\n   \"exports\": \"./index.js\",\n+  \"files\": [\n+    \"index.js\"\n+  ],\n   \"name\": \"x\",\n   \"type\": \"module\"\n }\n```\n\n### `main`\n\n`package.json`:\n\n```json\n{\n  \"files\": [\n    \"index.js\",\n    \"other.js\"\n  ],\n  \"main\": \"index.js\",\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n6:11-6:21: Unexpected legacy `main` field that does not encapsulate the package, it’s recommended to use an export map such as `\"exports\": \"./index.js\"`\n```\n\nFix:\n\n```diff\n@@ -1,9 +1,9 @@\n {\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.js\",\n     \"other.js\"\n   ],\n-  \"main\": \"index.js\",\n   \"name\": \"x\",\n   \"type\": \"module\"\n }\n```\n\n### `main-extra`\n\n`package.json`:\n\n```json\n{\n  \"exports\": \"./index.js\",\n  \"files\": [\n    \"index.js\"\n  ],\n  \"main\": \"index.js\",\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n6:11-6:21: Unexpected unused legacy `main` field with modern `exports`, remove it\n```\n\nFix:\n\n```diff\n@@ -3,7 +3,6 @@\n   \"files\": [\n     \"index.js\"\n   ],\n-  \"main\": \"index.js\",\n   \"name\": \"x\",\n   \"type\": \"module\"\n }\n```\n\n### `main-inferred`\n\n`package.json`:\n\n```json\n{\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"commonjs\"\n}\n```\n\nYields:\n\n```txt\n1:1-7:2: Unexpected inferred main export `./index.js`, it’s recommended to use an export map such as `\"exports\": \"./index.js\"`\n```\n\nFix:\n\n```diff\n@@ -1,4 +1,5 @@\n {\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.js\"\n   ],\n```\n\n### `main-invalid`\n\n`package.json`:\n\n```json\n{\n  \"files\": [\n    \"index.js\"\n  ],\n  \"main\": 1,\n  \"name\": \"x\",\n  \"type\": \"commonjs\"\n}\n```\n\nYields:\n\n```txt\n1:1-8:2: Unexpected inferred main export `./index.js`, it’s recommended to use an export map such as `\"exports\": \"./index.js\"`\n5:11-5:12: Unexpected non-string `main` field `1`\n```\n\nFix:\n\n```diff\n@@ -1,8 +1,8 @@\n {\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.js\"\n   ],\n-  \"main\": 1,\n   \"name\": \"x\",\n   \"type\": \"commonjs\"\n }\n```\n\n### `main-missing`\n\n`package.json`:\n\n```json\n{\n  \"files\": [\n    \"default.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"commonjs\"\n}\n```\n\nYields:\n\n```txt\n1:1-7:2: Unexpected missing main module, it’s recommended to use an export map such as `\"exports\": \"./index.js\"`\n```\n\nFix:\n\n```diff\n@@ -1,4 +1,5 @@\n {\n+  \"exports\": \"./default.js\",\n   \"files\": [\n     \"default.js\"\n   ],\n```\n\n### `main-not-found`\n\n`package.json`:\n\n```json\n{\n  \"files\": [\n    \"index.js\"\n  ],\n  \"main\": \"./missing.js\",\n  \"name\": \"x\",\n  \"type\": \"commonjs\"\n}\n```\n\nYields:\n\n```txt\n1:1-8:2: Unexpected inferred main export `./index.js`, it’s recommended to use an export map such as `\"exports\": \"./index.js\"`\n5:11-5:25: Unexpected missing file for `main` field `./missing.js`\n```\n\nFix:\n\n```diff\n@@ -1,8 +1,8 @@\n {\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.js\"\n   ],\n-  \"main\": \"./missing.js\",\n   \"name\": \"x\",\n   \"type\": \"commonjs\"\n }\n```\n\n### `main-resolve-commonjs`\n\n`package.json`:\n\n```json\n{\n  \"files\": [\n    \"index.js\"\n  ],\n  \"main\": \"index\",\n  \"name\": \"x\",\n  \"type\": \"commonjs\"\n}\n```\n\nYields:\n\n```txt\n5:11-5:18: Unexpected `main` field `index` that resolves to `./index.js` in CJS, this works but is slow and doesn’t work with `type: 'module', use the resolved value explicitly\n```\n\nFix:\n\n```diff\n@@ -1,8 +1,8 @@\n {\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.js\"\n   ],\n-  \"main\": \"index\",\n   \"name\": \"x\",\n   \"type\": \"commonjs\"\n }\n```\n\n### `main-resolve-module`\n\n`package.json`:\n\n```json\n{\n  \"files\": [\n    \"index.js\"\n  ],\n  \"main\": \"index\",\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n1:1-9:2: Unexpected inferred main export `./index.js`, it’s recommended to use an export map such as `\"exports\": \"./index.js\"`\n6:11-6:18: Unexpected `main` field `index` that does not resolve with `type: 'module'`, use an export map such as `\"exports\": \"./index.js\"`\n```\n\nFix:\n\n```diff\n@@ -1,8 +1,8 @@\n {\n+  \"exports\": \"./index.js\",\n   \"files\": [\n     \"index.js\"\n   ],\n-  \"main\": \"index\",\n   \"name\": \"x\",\n   \"type\": \"module\"\n }\n```\n\n### `name-missing`\n\n`package.json`:\n\n```json\n{\n  \"exports\": \"./index.js\",\n  \"files\": [\n    \"index.js\"\n  ],\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n1:1-7:2: Unexpected missing `name` field, expected a package name\n```\n\nFix:\n\n```diff\n@@ -3,5 +3,6 @@\n   \"files\": [\n     \"index.js\"\n   ],\n+  \"name\": \"x\",\n   \"type\": \"module\"\n }\n```\n\n### `npm-ignored`\n\n`package.json`:\n\n```json\n{\n  \"exports\": {\n    \".\": \"./index.js\",\n    \"./other\": \"./other.js\"\n  },\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"module\"\n}\n```\n\nYields:\n\n```txt\n4:16-4:28: Unexpected file `./other.js` at `exports['./other']` which is excluded from the npm package, add it to `files` in `package.json`\n```\n\nFix:\n\n```diff\n@@ -4,7 +4,8 @@\n     \"./other\": \"./other.js\"\n   },\n   \"files\": [\n-    \"index.js\"\n+    \"index.js\",\n+    \"other.js\"\n   ],\n   \"name\": \"x\",\n   \"type\": \"module\"\n```\n\n### `type-invalid`\n\n`package.json`:\n\n```json\n{\n  \"exports\": \"./index.js\",\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\",\n  \"type\": \"umd\",\n}\n```\n\nYields:\n\n```txt\n7:11-7:16: Unexpected invalid `type` value `umd`, expected `commonjs` or `module`\n```\n\nFix:\n\n```diff\n@@ -4,5 +4,5 @@\n     \"index.js\"\n   ],\n   \"name\": \"x\",\n-  \"type\": \"umd\"\n+  \"type\": \"module\"\n }\n```\n\n### `type-missing`\n\n`package.json`:\n\n```json\n{\n  \"exports\": \"./index.js\",\n  \"files\": [\n    \"index.js\"\n  ],\n  \"name\": \"x\"\n}\n```\n\nYields:\n\n```txt\n1:1-7:2: Unexpected missing `type` field, expected `type: 'commonjs'` or `'module'`\n```\n\nFix:\n\n```diff\n@@ -3,5 +3,6 @@\n   \"files\": [\n     \"index.js\"\n   ],\n-  \"name\": \"x\"\n+  \"name\": \"x\",\n+  \"type\": \"commonjs\"\n }\n```\n\n## Compatibility\n\nThis projects is compatible with maintained versions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `package-exports@1`,\ncompatible with Node.js 18.\n\n## Security\n\nThis package is safe.\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][open-source-guide-contribute].\n\n## License\n\n[MIT][file-license] © [Titus Wormer][wooorm]\n\n\u003c!-- Definitions --\u003e\n\n[api-package-exports]: #packageexportsfolder\n\n[api-export]: #export\n\n[api-result]: #result\n\n[badge-build-image]: https://github.com/wooorm/package-exports/actions/workflows/main.yml/badge.svg\n\n[badge-build-url]: https://github.com/wooorm/package-exports/actions\n\n[badge-coverage-image]: https://img.shields.io/codecov/c/github/wooorm/package-exports.svg\n\n[badge-coverage-url]: https://codecov.io/github/wooorm/package-exports\n\n[badge-downloads-image]: https://img.shields.io/npm/dm/package-exports.svg\n\n[badge-downloads-url]: https://www.npmjs.com/package/package-exports\n\n[file-license]: license\n\n[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[github-vfile]: https://github.com/vfile/vfile\n\n[npm-install]: https://docs.npmjs.com/cli/install\n\n[open-source-guide-contribute]: https://opensource.guide/how-to-contribute/\n\n[typescript]: https://www.typescriptlang.org\n\n[wooorm]: https://wooorm.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fpackage-exports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Fpackage-exports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fpackage-exports/lists"}