Description
- Rollup Plugin Name: @rollup/plugin-typescript
- Rollup Plugin Version: 11.1.3
- Rollup Version: 3.29.1
- TypeScript version: 5.2.2
- Operating System (or Browser): Ubuntu 22.04.3 LTS
- Node Version: 20.4.0
- Link to reproduction: https://stackblitz.com/edit/rollup-repro-su4nqt?file=tsconfig.json,tsconfig.base.json,rollup.config.js
Expected Behavior
I have two typescript config files: tsconfig.base.json and tsconfig.json.
In the tsconfig.base.json I have { compilerOptions: { module: "nodeNext" } }
.
tsconfig.json extends tsconfig.base.json.
When I run the typescript config, I expect that it takes the module: "nodeNext"
into account that I configured in the tsconfig.base.ts.
Actual Behavior
The plugin overwrites { compilerOptions: { module: "nodeNext" } }
with { compilerOptions: { module: "esNext" } }
. This produces the following error with TypeScript 5.2 and up (see also microsoft/TypeScript#54567):
(!) Plugin typescript: @rollup/plugin-typescript TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.
Additional Information
Cause of the bug
export const DEFAULT_COMPILER_OPTIONS: PartialCompilerOptions = {
module: 'esnext',
skipLibCheck: true
};
// ...
ts.parseJsonConfigFileContent(
{
...tsConfigFile,
compilerOptions: {
...DEFAULT_COMPILER_OPTIONS,
...tsConfigFile.compilerOptions
}
},
// ...
);
This block gets the JSON parsed tsConfigFile that's used to process the project (in the reproduction, thats ./tsconfig.json
), adds the default options to the compilerOptions
, and passes it on to TypeScript to completely parse the file, fill in defaults, etc.
However, if the tsconfig.json contains an extends which defines the module, the tsconfig.json ends up like this:
{
"compilerOptions": {
module: 'esnext',
skipLibCheck: true,
composite: true,
},
extends: "./tsconfig.base.json",
}
These compilerOptions take precedence over the one in the tsconfig.base.json, effectively overriding the project's module setting.
Workaround
Move / copy { compilerOptions: { module: "nodeNext" } }
to the tsconfig.json file.
This way, ...tsConfigFile.compilerOptions
overwrites the property from ...DEFAULT_COMPILER_OPTIONS
. However, it does lead to repetition that the extends
should solve.