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.
Both
require.resolve
andresolve-from
use theModule._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
.