Skip to content
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

How to tell --configPlugin to use specific tsconfig? #1713

Open
1 of 4 tasks
JoshMcCullough opened this issue Apr 24, 2024 · 3 comments
Open
1 of 4 tasks

How to tell --configPlugin to use specific tsconfig? #1713

JoshMcCullough opened this issue Apr 24, 2024 · 3 comments

Comments

@JoshMcCullough
Copy link

JoshMcCullough commented Apr 24, 2024

  • Rollup Plugin Name: typescript
  • Rollup Plugin Version: 11.1.5

Documentation Is:

  • Missing
  • Needed
  • Confusing
  • 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.

@lukastaegert
Copy link
Member

lukastaegert commented Apr 25, 2024

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

@JoshMcCullough
Copy link
Author

JoshMcCullough commented Apr 25, 2024

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).

@danielvy
Copy link

danielvy commented May 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants