Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not exporting types in esm #1246

Closed
0xDing opened this issue Aug 21, 2022 · 3 comments
Closed

Not exporting types in esm #1246

0xDing opened this issue Aug 21, 2022 · 3 comments

Comments

@0xDing
Copy link

0xDing commented Aug 21, 2022

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"

@krivin
Copy link

krivin commented Aug 21, 2022

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.

@jroru
Copy link

jroru commented Sep 19, 2022

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

@stale stale bot added the x⁷ ⋅ stale label Nov 22, 2022
@stale
Copy link

stale bot commented Nov 28, 2022

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 stale bot closed this as completed Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants