brillout / vite-plugin-mdx

Vite Plugin for MDX
MIT License
115 stars 36 forks source link

fix: package resolution with local vite clone #12

Closed aleclarson closed 3 years ago

aleclarson commented 3 years ago

Both require.resolve and resolve-from use the Module._resolveLookupPaths function, which searches the node_modules of the entry module (vite/bin/vite.js) when a package is not found in the node_modules of a given root. This leads to false positives when a local clone of vite is used, since vite has preact in its devDependencies.

Even if a local clone of vite is not being used, the global node_modules are searched, which can also lead to false positives if you have preact or @mdx-js/react installed globally for some odd reason.

To solve these issues, I've installed find-dependency, a small package I wrote back in 2017, which imitates Node's resolution algorithm without the entry node_modules fallback and (optionally) without the global node_modules fallback.

Here's the source code of find-dependency.

brillout commented 3 years ago

Makes sense.

brillout commented 3 years ago

Btw. let me know if you want us to move the repo under your name https://github.com/aleclarson/vite-plugin-mdx