Skip to content

package.json: define explicit exports to support CJS require in Node 18+ #1402

@thienvc

Description

@thienvc

Currently, the generated package.json on NPM lacks the require condition for ./eslint-plugin, causing builds to fail in Node 18+ environments (ERR_PACKAGE_PATH_NOT_EXPORTED).

By explicitly defining the exports map in the source package.json, we ensure the published package includes the correct require entry pointing to the compiled JS, allowing tools like jiti/eslint to load the plugin correctly.

"exports": {
    ".": {
      "types": "./dist/types/index.d.ts",
      "import": "./dist/index.js",
      "require": "./dist/index.cjs.js"
    },
    "./dist/*": {
      "import": "./dist/*",
      "types": "./dist/*"
    },
    "./loader": {
      "types": "./loader/index.d.ts",
      "import": "./loader/index.js",
      "require": "./loader/index.cjs.js"
    },
    "./eslint-plugin": {
      "types": "./eslint-plugin/dist/index.d.ts",
      "import": "./eslint-plugin/dist/index.js",
"require": "./eslint-plugin/dist/index.js",
	  "default": "./eslint-plugin/dist/index.js"
    }
  },

need add "require": "./eslint-plugin/dist/index.js",
"default": "./eslint-plugin/dist/index.js"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions