aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.23k stars 44 forks source link

Error [ERR_MODULE_NOT_FOUND] in slightly modified demo when using tsconfig path alias #98

Closed wvhulle closed 1 year ago

wvhulle commented 1 year ago

To be able to run the demo I had to modify a couple of things. The "link" import in package.json has to be updated. While installing it required me to install rimraf tsup-node and yarn globally. I don't want to do that, so I change the dependency to an npm dependency. Then I had to change the module resolution method for the modules to be resolved. Eventually I managed to write a test function in a "$lib" folder. I set up an alias and imported it in vite.config.ts. However, the module is not resolved.

Here is my reproduction https://github.com/wvhulle/vite-tsconfig-paths-bug

aleclarson commented 1 year ago

it required me to install rimraf tsup-node and yarn globally

The rimraf and tsup-node commands are provided by running pnpm install in the root directory of this repository, so those don't need global dependencies.

But yes, the yarn global dependency is problematic and should be fixed. 👍

Then I had to change the module resolution method for the modules to be resolved.

Hmmm, the moduleResolution should already be node as it's inherited from the root tsconfig.json. (Oh I see your reproduction doesn't have the extends property for some reason...)

However, the module is not resolved.

Modules imported in vite.config.ts do not have Vite's path resolution applied (as of Vite v4), so this plugin won't help you there.