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

Compiler Option moduleResolution is ignored and only dependend on module type #1375

Closed
IIIMADDINIII opened this issue Dec 13, 2022 · 1 comment · Fixed by #1453
Closed

Compiler Option moduleResolution is ignored and only dependend on module type #1375

IIIMADDINIII opened this issue Dec 13, 2022 · 1 comment · Fixed by #1453

Comments

@IIIMADDINIII
Copy link

Expected Behavior

I expected that the moduleResolution set in the tsconfig.json is respected and not always overwritten by setModuleResolutionKind.

function setModuleResolutionKind(parsedConfig: ParsedCommandLine): ParsedCommandLine {
const moduleKind = parsedConfig.options.module;
const moduleResolution =
moduleKind === ModuleKind.Node16
? ModuleResolutionKind.Node16
: moduleKind === ModuleKind.NodeNext
? ModuleResolutionKind.NodeNext
: ModuleResolutionKind.NodeJs;
return {
...parsedConfig,
options: {
...parsedConfig.options,
moduleResolution
}
};
}

Actual Behavior

In a Module with type: commonjs in the package.json it is not possible to have a valid bundle and also use NodeNext as the moduleResolution.

Additional Information

The Rollup Typescript Plugin always overrides the moduleResolution option based on the module option.

When in the tsconfig.json the module option is set to NodeNext the moduleResolution is set to NodeNext. Because in package.json the type is set to commonjs, typescript is compiling to commonjs. Rollup dose't understand commonjs out of the box, so the dependency module dose't get bundled. All of this is what i am expecting!! No issue so far.

To make the output of typescript compatible with rollup i change the module type to ESNext. This config can be compiled with Typescript without errors because typescript is using the moduleResolution of the tsconfig.json file (NodeNext)!!

In Rollup (with Typescript Plugin) this now dose't compile anymore. The reason is, that the typescript plugin is overriding the moduleResolution to node. So typescript can not find the declarations anymore. This is because i'm declaring the exports of the dependency with the exports field in the package.json which typescript ignores for types when it is set to node moduleResolution. This is due to the setModuleResolutionKind function in src/options/tsconfig.ts.

function setModuleResolutionKind(parsedConfig: ParsedCommandLine): ParsedCommandLine {

I don't know why this function exists and is implemented like it is. When i change this function to not change the moduleResolution option, everything works as expected.

Maybe it is better to not override this option when ES Modules are specified? I think at least we should keep a way to manually set the moduleResolution option.

@Polve
Copy link

Polve commented Mar 12, 2023

Can you please give us more details on which modification make to the (rollup?) sources to overcome this problem that is blocking me? Thanks!

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

Successfully merging a pull request may close this issue.

2 participants