Skip to content

Conversation

@Yofou
Copy link

@Yofou Yofou commented Oct 11, 2025

TLDR

when tsconfig.json field compilerOptions.moduleResolution = "bundler", i was getting Unable to resolve path to module

Before package json change

image

After

image

@mcous
Copy link
Owner

mcous commented Oct 12, 2025

Hey @Yofou, thanks for the PR! Are you able to share a minimal reproduction of the resolution issue you described? I'm not opposed to this change in theory, but I'm unable to reproduce any issue when using moduleResolution: bundler myself. I spun up a quick new repo and TS was able to resolve vitest-when properly with bundler

I want to make sure I understand the issue properly before messing around in exports

@Yofou
Copy link
Author

Yofou commented Oct 12, 2025

@mcous

Ack! I should have confirmed this before making the PR, but the errors are actually coming from eslint-plugin-import and has nothing to do with moduleResolution field! (my bad)

here is the minimum repo that should match what we have at my job!
https://stackblitz.com/~/github.com/Yofou/vitest-dev-vitest-nvru1bbg?file=test/basic.test.js&initialPath=/__vitest__/

NOTE: Make sure you have eslint installed in your editor, to see the errors I have in my description

my best guess on why this is happening is that somewhere when the plugin resolves imports it is happening in a cjs environment, hence fails to resolve, as it can't find exports.require field in the vitest-when package json.

although I think it'd be misleading to add require field because you don't distribute a cjs, so exports.defaultshould be adequate!

@mcous
Copy link
Owner

mcous commented Oct 13, 2025

@Yofou eslint-plugin-import does not support the exports field at all. So, to support packages that use exports, you need to use an alternative resolver. In your StackBlitz, you're using eslint-import-resolver-alias, which is where the error is coming from. I checked out the source code of this module, and I found that it's quite old and seems to sketchily monkeypatch Node's module system.

Have you considered switching to a more modern resolver, like eslint-import-resolver-typescript, with proper support for the exports field? In your stackblitz, if I replace the alias resolver with typescript, everything works correctly.

vitest-when is specifying its exports correctly, so it seems like this is more of an issue on your repo's end rather than something that should change here

@Yofou
Copy link
Author

Yofou commented Oct 13, 2025

@mcous Gotcha! I'm convinced that this isn't necessarily an issue with your package anymore.

although it's interesting this has only come up now with this package. we build tons of internal packages ourselves (that uses a very similar exports field as vitest-when does). what's more annoying that this specific eslint plugin is coming from a company wide eslint config, which is used in pretty much all our repo's so this'll be harder for us to budge on (but not impossible!)

but thank you for the spear heading this for us (you didn't need to go as far as finding alternative)!

Worst comes to worsts I'll monkey patch our node_modules, to update vitest-when package json, even though plugin resolver though shouldn't be failing, it for odd reason is, for this package.

@Yofou Yofou closed this Oct 13, 2025
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 this pull request may close these issues.

2 participants