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

fix: package resolution with local vite clone #12

Merged
merged 1 commit into from
Mar 11, 2021
Merged

Conversation

aleclarson
Copy link
Collaborator

@aleclarson aleclarson commented Mar 11, 2021

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.

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.
@aleclarson aleclarson requested a review from brillout March 11, 2021 16:40
@brillout brillout merged commit 6ae8c17 into master Mar 11, 2021
@brillout
Copy link
Owner

Makes sense.

@brillout
Copy link
Owner

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

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