File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -951,12 +951,17 @@ export const requireResolveFromRootWithFallback = (
951
951
root : string ,
952
952
id : string
953
953
) : string => {
954
+ const paths = _require . resolve . paths ?.( id ) || [ ]
954
955
// Search in the root directory first, and fallback to the default require paths.
955
- const fallbackPaths = _require . resolve . paths ?.( id ) || [ ]
956
- const path = _require . resolve ( id , {
957
- paths : [ root , ...fallbackPaths ]
958
- } )
959
- return path
956
+ paths . unshift ( root )
957
+
958
+ // Use `resolve` package to check existence first, so if the package is not found,
959
+ // it won't be cached by nodejs, since there isn't a way to invalidate them:
960
+ // https://github.com/nodejs/node/issues/44663
961
+ resolve . sync ( id , { basedir : root , paths } )
962
+
963
+ // Use `require.resolve` again as the `resolve` package doesn't support the `exports` field
964
+ return _require . resolve ( id , { paths } )
960
965
}
961
966
962
967
// Based on node-graceful-fs
You can’t perform that action at this time.
0 commit comments