-
-
Notifications
You must be signed in to change notification settings - Fork 600
[TypeScript] Module resolution doesn't work in rollup.config.ts when using modern project settings #1662
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
Comments
Same issue encountered. |
Alternatively
Which again isn't nice, but allows you to keep using a TS config file. |
Might be off-topic, but here is another workaround to keep the typings: // rollup.config.ts
import _eslint from '@rollup/plugin-eslint';
import _typescript from '@rollup/plugin-typescript';
// NOTE: remove once import errors are fixed for their respective packages
const eslint = _eslint as unknown as typeof _eslint.default;
const typescript = _typescript as unknown as typeof _typescript.default;
// ...
export default {
// ...
plugins: [eslint(), typescript()]
}; |
This issue sounds like microsoft/TypeScript#58890 The cause appears to be related to how TypeScript classifies imports. microsoft/TypeScript#58890 (comment) concluded that if the In the case of This issue is fixable, but it will mean duplicating EDIT: This also affects |
@Arnesfield's workaround failed for me with the following error:
I had to specify the type explicitly for it to work. In the case of import _rollupCommonJs from "@rollup/plugin-commonjs";
import _rollupTypescript, {type RollupTypescriptOptions} from "@rollup/plugin-typescript";
const rollupCommonJs = _rollupCommonJs as unknown as (options?: unknown) => Plugin;
const rollupTypescript = _rollupTypescript as unknown as (options?: RollupTypescriptOptions) => Plugin; I hope this helps. |
Interested to find out that no one pick this, I believe at least some of the maintainer should leave a message guiding us a expected solution to fix this. For me, I would prefer to add |
@Silic0nS0ldier Your answer is almost correct, but there is a singular solution to this problem.
{
"name": "@rollup/plugin-typescript",
"exports": {
"import": {
"types": "./types/index.d.mts",
"default": "./dist/es/index.js"
},
"require": {
"types": "./types/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
} This would require creating a new Update: It looks like there's already a PR open which does exactly this: #1782 Just need to wait for a test fix and a merge! |
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. ⓘ |
. |
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. ⓘ |
Expected Behavior
Compile as usual. Use
npm run bug
in my repl to see what happens.Actual Behavior
Produces errors when compiling:
Additional Information
Key ingredients are:
"type": "module"
in package.json"moduleResolution": "NodeNext"
or"Node16"
in tsconfig.jsonThe workaround is to use a JavaScript config file, so this is really the smallest of inconveniences, but it's something to fix nonetheless.
The text was updated successfully, but these errors were encountered: