plugins: [@rollup/plugin-typescript] tsconfig declarationDir is ignored when using single file output
- Rollup Plugin Name: plugin-typescript
- Rollup Plugin Version: 8.3.4
- Rollup Version: 2.77.2
- Operating System (or Browser): Windows
- Node Version: v14.19.1
- Link to reproduction (⚠️ read below): https://replit.com/@BobCarrot/rollup-plugin-typescript-declarationDir-error
Expected Behavior
Declarations generated at the specified location
Actual Behavior
Declarations generated at the same directory as the output file.
Additional Information
I’m using api-extractor to rollup d.ts files into a single one, so the declarations are output at a place that will be removed after
processing.
This works at version 8.3.1 with a problem that it generates file at relative location under output directory, that is when declarationDir is types and output.file is dist/index.js, declarations will be under dist/types. But after my collegue updated to 8.3.4 (by using ^8.3.1 in package.json), the behavior changes to that declarations generated at dist/, and the build progress breaks since api-extractor can’t find the desired entry for d.ts rollup.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 29
- Comments: 23
Commits related to this issue
- chore: emitting declarations only from `tsc` cmd due to issues in rollup plugin https://github.com/rollup/plugins/issues/1230 — committed to dominikbulaj/react-scroll-into-view by dominikbulaj 4 years ago
- Pin @rollup/plugin-typescript to v8.3.3 until issue rollup/plugins#1230 is resolved — committed to Basssiiie/OpenRCT2-FlexUI by Basssiiie 4 years ago
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. ⓘ
I found that there will be similar problems in the case of multi-file output
the error log
Is this caused by the same problem?
+1 to get this fixed in the latest Rollup version 🙏
Having the same problem with the latest versions : @rollup/plugin-typescript: Path of Typescript compiler option ‘declarationDir’ must be located inside the same directory as the Rollup ‘file’ option.
I have back to those version and everything worked well :
“@rollup/plugin-commonjs”: “^25.0.3”, “@rollup/plugin-json”: “^6.1.0”, “@rollup/plugin-node-resolve”: “^15.1.0”, “@rollup/plugin-terser”: “^0.4.4”, “@rollup/plugin-typescript”: “^11.1.2”,
I got the same issue with 8.3.4. Now I have to create new tsconfig.types.json with declaration config “compilerOptions”: { “declaration”: true, “declarationDir”: “./dist/types”, “emitDeclarationOnly”: true, } then use tsc command to generate d.ts to specific folder. It works but it’s ugly. Hope it could be fixed asap.
I’m not sure how you managed to misunderstand the very clear language in the message that the bot posted. but good luck to you.
for onlookers and people who run across this issue in the future, we openly welcome community help to resolve this. the team of maintainers for roll-up is extremely small, and we are stretched extremely thin. we all have jobs and families.
After some debugging, I’ve noticed that this issue comes up if you have a subfolder for the
dirproperty.E.g this is the config we had
The error went away when I changed
build/esmto justbuildThe problem is still here.
Has this problem been solved yet
Can we re-open this? Its clearly not fixed and an outstanding issue.
I got the issue as well. Reverting back to version 8.3.3 fixes the issue, so it seems it was introduced in the 8.3.4 release. The only change in that release is this; #1201, which may very well be the cause (also there’s other people talking about problems there as well).
Easiest temporary fix for now: revert back to 8.3.3 and pin this version in your package.json.
@himanshuchawla009 please do not post “me too,” “+1” type replies. They spam anyone who has notifications on for issues (e.g. all maintainers). Please use the reaction buttons on the original post in the issue instead.
Also confirmed.
In
tsconfig.jsonI have:"declaration": falseand inrollup.config.jsI gotWhen rollup runs declaration file(s) are placed in the output directory and not specified (
'./types')helped, when install this version
@rollup/plugin-typescript: ^11.0.0
I use a a hack way to avoid error . use ts to generate .d.ts . use rollup to build …
I’m sticking with the old one at present. I don’t believe I saw anything about this getting fixed…
I’m also having this problem with the latest version. And I think I found the problem with the recently merged PR #1201. Please correct me if my analysis is wrong.
https://github.com/rollup/plugins/blob/0bbb4fde7ea52f29769d630269982524e73a7ee9/packages/typescript/src/index.ts#L141-L155
Asumming the
parsedOptions.options.declarationis true and we’re using single file output. TheoutputOptions.dirwill beundefined, and thebaseDirwill be set to theparsedOptions.options.declarationDirvalue or fallback toparsedOptions.options.outDirif its not set (line 141). And sincebaseDiris now defined, the code generation will not be skipped and output files will be generated (line 149). This seems to be a solid logic, however on line 153 the filename for the file being generated is normalized and make relative to thebaseDir.https://github.com/rollup/plugins/blob/0bbb4fde7ea52f29769d630269982524e73a7ee9/packages/typescript/src/index.ts#L153
So for example, if user set declarationDir to
types, andfoo/bar.d.tsis to be generated then: the expected filename relative to the output will betypes/foo/bar.d.tsbut the actual filename insteadfoo/bar.d.tsthis is because:we can see, that whatever value the
declarationDirholds will be useless in single file output since the final filename will always be made relative to thedeclarationDiritself.