plugins
plugins copied to clipboard
How to tell `--configPlugin` to use specific `tsconfig`?
- Rollup Plugin Name: typescript
- Rollup Plugin Version: 11.1.5
Documentation Is:
- [ ] Missing
- [ ] Needed
- [ ] Confusing
- [x] Not Sure?
Please Explain in Detail...
I am getting the error:
[!] (plugin typescript) RollupError: [plugin typescript] @rollup/plugin-typescript: You are using one of Typescript's compiler options 'declaration', 'declarationMap' or 'composite'. In this case 'outDir' or 'declarationDir' must be specified to generate declaration files. ... at validatePaths (/home/josh/.../node_modules/@rollup/plugin-typescript/dist/cjs/index.js:423:21)
I am running:
rollup -c rollup-lambdas.config.ts --configPlugin typescript
It appears that the plugin is using my tsconfig.json
instead of tsconfig-lambdas.json
. I added logging to @rollup/plugin-typescript/dist/cjs/index.js:423
(console.log(compilerOptions)
) and I get this output:
{
// ...
configFilePath: '/home/josh/.../tsconfig.json',
}
To get around this I renamed the original tsconfig.json
to tsconfig-main.json
and tsconfig-lambdas.json
to tsconfig.json
, now the plugin uses the "correct" (default) tsconfig and my build works.
How can I tell the plugin to use my other tsconfig
?
Your Proposal for Changes
Not sure.
From the docs https://rollupjs.org/command-line-interface/#configplugin-plugin:
This option supports the same syntax as the --plugin option i.e., you can specify the option multiple times, you can omit the @rollup/plugin- prefix and just write typescript and you can specify plugin options via
={...}
.
This last part is how you can specify such options while the options for the TypeScript plugin can be found here https://github.com/rollup/plugins/blob/master/packages/typescript/README.md#tsconfig
I saw that and I did try this (sorry, should have specified in the OP):
rollup -c rollup-lambdas.config.ts --configPlugin "typescript={tsconfig:'tsconfig-lambdas.json'}" --bundleConfigAsCjs
This gives me:
[!] (plugin typescript) RollupError: [plugin typescript] @rollup/plugin-typescript: Couldn't process compiler options at getRollupError (/home/josh/Projects/teslagov/clarakm-mono-repo/ts/node_modules/rollup/dist/shared/parseAst.js:282:41) at Object.error (/home/josh/Projects/teslagov/clarakm-mono-repo/ts/node_modules/rollup/dist/shared/parseAst.js:278:42) at Object.error (/home/josh/Projects/teslagov/clarakm-mono-repo/ts/node_modules/rollup/dist/shared/rollup.js:804:32) at emitParsedOptionsErrors (/home/josh/Projects/teslagov/clarakm-mono-repo/ts/node_modules/@rollup/plugin-typescript/dist/cjs/index.js:378:17) at Object.buildStart (/home/josh/Projects/teslagov/clarakm-mono-repo/ts/node_modules/@rollup/plugin-typescript/dist/cjs/index.js:788:13) at /home/josh/Projects/teslagov/clarakm-mono-repo/ts/node_modules/rollup/dist/shared/rollup.js:989:40 at async Promise.all (index 0) at PluginDriver.hookParallel (/home/josh/Projects/teslagov/clarakm-mono-repo/ts/node_modules/rollup/dist/shared/rollup.js:917:9) at /home/josh/Projects/teslagov/clarakm-mono-repo/ts/node_modules/rollup/dist/shared/rollup.js:20825:13 at catchUnfinishedHookActions (/home/josh/Projects/teslagov/clarakm-mono-repo/ts/node_modules/rollup/dist/shared/rollup.js:20381:16)
It does seem like documentation is lacking for the plugin-args feature (and I can't get it to work).
I find that using Typescript Rollup config files can be challenging and frustrating if you need to use different Typescript config options for your main source code.
By the way, Rollup doesn't follow standard Typescript behavior when resolving tsconfig.json
files like it should, so you can't put your Rollup config ts file in subdirectory and put a different tsconfig.json
there like one would expect. It also seems that @rollup/plugin-typescript
plugin reuses the last loaded tsconfig.json
.
With that, the way I was able to make it work is:
Create basic tsconfig.rollup.json
just for Rollup config script.
Use rollup -c rollup.config.ts --configPlugin typescript={tsconfig:'tsconfig.rollup.json'}
to run Rollup.
In your rollup.config.ts
, explicitly specify the tsconfig.json
for your code:
import rollupTypescript from "@rollup/plugin-typescript";
import type { RollupOptions } from "rollup";
const config: RollupOptions = {
...
plugins: [
rollupTypescript({
// Source tsconfig
tsconfig: "tsconfig.json"
}),
],
}
export default config;
I hope this will be addressed sometime to make using Typescript config in Rollup less cumbersome or at least documented more clearly.
Thanks, I'll give it a try.
For anyone else who was struggling with the workaround in https://github.com/rollup/plugins/issues/1713#issuecomment-2096028981, I needed to escape the quotes (it looks like the yargsparser used by rollup strips quotation marks):
rollup -c rollup.config.ts --configPlugin typescript={tsconfig:\'tsconfig.rollup.json\'}