-
-
Notifications
You must be signed in to change notification settings - Fork 599
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
@rollup/plugin-node-resolve typings don't work with TypeScript 4.7's moduleResolution: Node16 #1192
Comments
Looking at the source (rather than the distributed package), maybe using: "exports": {
".": {
"import": {
"types": "./types/index.d.mts",
"default": "./dist/es/index.js"
},
"default": {
"types": "./types/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
}, and symlinking |
Would this be good enough? "exports": {
".": {
"types": "./types/index.d.ts",
"import": "./dist/es/index.js",
"require": "./dist/cjs/index.js"
}
}, I don't think the |
The PR in #1196 should fix these I believe? |
It does (when not specifying
Awesome, I think that would fix it, yeah. |
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. ⓘ |
Cannot find module '@rollup/plugin-node-resolve' i am runing yarn command after that facing this issue . i can not understand what is the issue |
Expected Behavior
The typings supplied by @rollup/plugin-node-resolve should still work with TypeScript 4.7 when ECMAScript Module support for Node.js is enabled (i.e.
"moduleResolution": "Node16",
orNodeNext
is configured).Actual Behavior
TypeScript can't find the typings anymore, because is uses the contents of the
exports
-field to find them and the top-leveltypes
-filed is no longer used. This is analogous to how Node.js no longer uses themain
ormodule
fields whenexports
is present and is explained somewhat in the announcement blog post.Additional Information
I experimented a bit with how to fix this.
Simply adding the
types
-field toexports
, like this:only fixes importing the named export (and is discouraged). Importing the default export (
import nodeResolve from "@rollup/plugin-node-resolve"
) at first seems to work, but it doesn't result in a callable function. I think I understand now why that happens:package.json
does not specify"type": "module"
, so.{js,ts}
-files are specified as CommonJSindex.d.ts
file is not a.d.mts
file and therefore assumed to be CommonJSdefault
export when getting imported)module.exports = { default: /* ... */ }
and therefore forbids directly calling the default export (it would allow callingnodeResolve.default
, but that doesn't exist at run-time)From what I understand, a complete fix would need to tell TypeScript, for which module system the typings are:
d.mts
/d.cts
-filenamestype
-field (which already exists asdist/es/package.json
)Additionally, there's the question of either letting TypeScript find the typings automatically based on the file name or explicitly specifying the location of the typing files, which would look like this:
But I think that is very verbose and error-prone, so I'd rather suggest keeping the
exports
-field as-is and switching to this file structure:The existing
package.json
can even be removed later on, by renaming the files like this:What do you think?
The text was updated successfully, but these errors were encountered: