You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[@rollup/plugin-typescript] tsconfig declarationDir is ignored when using single file output #1230
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.
@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.
Reacted by himanshuchawla009, Santiago Rios Olaya and Reed Hermes
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.
Reacted by Dominik Bułaj, Carrot, Ovidiu-Deliu, Robert Pearce, Jakka Prihatna, JGO, Raissa Pyyne Correia and Rustem Zinnatullin
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.
Reacted by Ovidiu-Deliu, stephen kurtz and Robert Pearce
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.
Asumming the parsedOptions.options.declaration is true and we're using single file output.
The outputOptions.dir will be undefined, and the baseDir will be set to the parsedOptions.options.declarationDir value or fallback to parsedOptions.options.outDir if its not set (line 141).
And since baseDir is 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 the baseDir.
So for example, if user set declarationDir to types, and foo/bar.d.ts is to be generated then:
the expected filename relative to the output will be types/foo/bar.d.ts
but the actual filename instead foo/bar.d.ts this is because:
we can see, that whatever value the declarationDir holds will be useless in single file output since the final filename will always be made relative to the declarationDir itself.
This appears to still be an issue as of the latest version, v9.0.0. Locking the version to 8.3.3 seems to be the only way to keep the original behavior working.
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. ⓘ
Reacted by Xan Torres, Kaique Nunes, sdadaniel, Cristian Eriomenco, Sam (Protosus), M. Steller, Ian Copp, Blake B., kwright02, wxj123654 and 16 more
Reacted by Basssiiie, Melissa Hoo, Pushpendra Singh, Pop Razvan, Santiago Rios Olaya, Mykhaylo Ryechkin and Matheus Teles
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.
Reacted by Sergei Lobanov, Mark Hughes, Alexander Ozhigin, Egor Shum and swiing
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 :
Reacted by Nandik Devbhuti, Matheus Teles, Mohit Meena, Peter Djeneralovic, I Am Kio, Hernán Massad, Eduard Paul, Randy808, Bekzhan Seitkali, Jae-Yeol and 1 more
Encountered the same error RollupError: [plugin typescript] @rollup/plugin-typescript: Path of Typescript compiler option 'declarationDir' must be located inside the same directory as the Rollup 'file' option.
Fix:
Just updated "declarationDir": "types" to "declarationDir": "dist/types" in tsconfig.json and this fixed it.
Checking the plugin's implementation, it looks like the declarationDirmust be inside a directory controlled by rollup, in case a different plugin wants to do something with the declaration files. So having the types outside of an output dir (such as dist/types when the output is on dist/cjs), would not respect that. See here:
When generating declaration files, the outDir must be set and be pointed to Rollup's output dir (or some subfolder). This allows us to use Rollup's asset emit API, and other plugins can then intercept these assets to potentially bundle the declaration files later.
However, there is a workaround, such as this one found by zeakd. Basically there are two different rollup configs:
In one, the typescript is compiled into cjs and the types are generated. This one uses the dist dir as output dir, but renames the index to be in a cjs subfolder. This allows the usage of dist/types as an output dir for the declaration files.
In the other, the typescript is compiled into es but without emitting declaration files. This config is as usual.
The main disadvantage of this approach is that now you have to maintain two configs, though you can probably have a common config object and spread the common configuration between them.
Activity
dominikbulaj commentedon Aug 1, 2022
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')himanshuchawla009 commentedon Aug 2, 2022
shellscape commentedon Aug 2, 2022
@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.
Alpha0723 commentedon Aug 3, 2022
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.
chore: emitting declarations only from `tsc` cmd
Basssiiie commentedon Aug 12, 2022
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.
Pin @rollup/plugin-typescript to v8.3.3 until issue rollup/plugins#1230…
IronGeek commentedon Sep 1, 2022
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.
plugins/packages/typescript/src/index.ts
Lines 141 to 155 in 0bbb4fd
Asumming the
parsedOptions.options.declarationis true and we're using single file output.The
outputOptions.dirwill beundefined, and thebaseDirwill be set to theparsedOptions.options.declarationDirvalue or fallback toparsedOptions.options.outDirif its not set (line 141).And since
baseDiris 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 the
baseDir.plugins/packages/typescript/src/index.ts
Line 153 in 0bbb4fd
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 be
types/foo/bar.d.tsbut the actual filename instead
foo/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.rpearce commentedon Oct 11, 2022
This appears to still be an issue as of the latest version,
v9.0.0. Locking the version to8.3.3seems to be the only way to keep the original behavior working.yangliguo7 commentedon Nov 23, 2022
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?
stale commentedon Feb 2, 2023
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. ⓘ
melissarh57 commentedon Feb 17, 2023
Did this ever get fixed? Or still just sticking with old rollup version for now?
rpearce commentedon Feb 18, 2023
I'm sticking with the old one at present. I don't believe I saw anything about this getting fixed...
2 remaining items
deansimcox commentedon Aug 23, 2023
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 justbuildsoeasyjx commentedon Dec 11, 2023
Has this problem been solved yet
rudevich commentedon May 5, 2024
The problem is still here.
cristian-eriomenco commentedon May 21, 2024
Can we re-open this? Its clearly not fixed and an outstanding issue.
shellscape commentedon May 21, 2024
@cristian-eriomenco read this in its entirety and you'll have your answer: #1230 (comment)
cristian-eriomenco commentedon May 21, 2024
Understood. Not going to fix it. Thanks for clarification.
shellscape commentedon May 21, 2024
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.
eimenanacreado commentedon Dec 28, 2024
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",
sbeka commentedon Feb 19, 2025
helped, when install this version
@rollup/plugin-typescript: ^11.0.0
steebtom commentedon Mar 16, 2025
Encountered the same error
RollupError: [plugin typescript] @rollup/plugin-typescript: Path of Typescript compiler option 'declarationDir' must be located inside the same directory as the Rollup 'file' option.Fix:
Just updated
"declarationDir": "types"to"declarationDir": "dist/types"in tsconfig.json and this fixed it.package.json
"@rollup/plugin-babel": "6.0.4","@rollup/plugin-commonjs": "28.0.3","@rollup/plugin-node-resolve": "16.0.1","@rollup/plugin-terser": "0.4.4","@rollup/plugin-typescript": "12.1.2","@types/react": "19.0.10","react": "19.0.0","react-dom": "19.0.0","rollup": "4.35.0","rollup-plugin-peer-deps-external": "2.2.4","rollup-plugin-postcss": "4.0.2","typescript": "5.8.2"tsconfig.json
{ "compilerOptions": { "target": "es5", "module": "esnext", "lib": ["dom", "dom.iterable", "esnext"], "jsx": "react", "declaration": true, "declarationDir": "dist/types", "outDir": "dist", "strict": true, "moduleResolution": "node", "allowSyntheticDefaultImports": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, "include": ["src"] }Hope this helps someone.
Fix rollup error
eakarpov commentedon Sep 12, 2025
12.* version still has the error (11.* is ok)
RahulCh010 commentedon Nov 28, 2025
Any idea how to resolve this for multi-file output? Even reverting to v11 didn't help for me
ychavoya commentedon Nov 28, 2025
Hello! Regarding the multi-file output.
Checking the plugin's implementation, it looks like the
declarationDirmust be inside a directory controlled by rollup, in case a different plugin wants to do something with the declaration files. So having the types outside of an output dir (such asdist/typeswhen the output is ondist/cjs), would not respect that. See here:However, there is a workaround, such as this one found by zeakd. Basically there are two different rollup configs:
cjsand the types are generated. This one uses thedistdir as output dir, but renames the index to be in acjssubfolder. This allows the usage ofdist/typesas an output dir for the declaration files.esbut without emitting declaration files. This config is as usual.The main disadvantage of this approach is that now you have to maintain two configs, though you can probably have a common config object and spread the common configuration between them.
Here's an example I managed to make:
rollup.config.jstsconfig.json:{ "compilerOptions": { "target": "es5", "sourceMap": true, "inlineSources": true, }, "exclude": [ "node_modules" ] }This provides the following result:
Hope this helps!
Update `tsconfig(-plugins).json` so `declarationDir` is in `*dist/`