plugins icon indicating copy to clipboard operation
plugins copied to clipboard

Not exporting types in esm

Open 0xDing opened this issue 2 years ago • 2 comments

  • Rollup Plugin Name: @rollup/pluginutils
  • Rollup Plugin Version: 4.2.1
  • Rollup Version: 2.77.3
  • Operating System (or Browser): macOS 12.5.1
  • Node Version: v18.7.0
  • Link to reproduction (⚠️ read below): https://github.com/0xDing/reproduction-rollup-pluginutils-esm-bug

Expected Behavior

Since @rollup/pluginutils already provides the type definition file, it should be able to be compiled successfully by tsc.

Actual Behavior

However, when it is introduced as an esm package, the following compilation error occurs:

 error TS7016: Could not find a declaration file for module '@rollup/pluginutils'. '/Users/ding/Projects/q/node_modules/@rollup/pluginutils/dist/es/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/rollup__pluginutils` if it exists or add a new declaration (.d.ts) file containing `declare module '@rollup/pluginutils';`

Additional Information

add exports.types to package.json could fix it.

diff --git a/package.json b/package.json
index 6c9a2851e043cb86d15ad234d2aea5bbff319f81..68ef585105c1ba97dcd1367e5d219906069a1b30 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,8 @@
   "type": "commonjs",
   "exports": {
     "require": "./dist/cjs/index.js",
-    "import": "./dist/es/index.js"
+    "import": "./dist/es/index.js",
+    "types": "./types/index.d.ts"
   },
   "engines": {
     "node": ">= 8.0.0"

0xDing avatar Aug 21 '22 11:08 0xDing

I was also just hit by this yesterday. Aside from pluginutils are node-resolve and commonjs plugins also affected. Seems like this is the correct way of specifying it:

  "exports": {
    ".": {
      "require": "./dist/cjs/index.js",
      "import": "./dist/es/index.js",
      "types": "./types/index.d.ts"
    }
  },

But maybe exports can be removed entirely, since main, module, and types are already specified.

Also note that even with this fixed, the default exports of the plugins are broken causing e.g. commonjs from import commonjs from "@rollup/plugin-commonjs"; to have an incorrect type. Maybe related to this or this. Using import { default as commonjs } from "@rollup/plugin-commonjs"; instead works.

krivin avatar Aug 21 '22 14:08 krivin

Also experiencing this, am I good to submit a PR or is there a discussion to be had beforehand?

jroru avatar Sep 19 '22 20:09 jroru

Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.

stale[bot] avatar Nov 28 '22 04:11 stale[bot]