less / less.js

Less. The dynamic stylesheet language.
http://lesscss.org
Apache License 2.0
16.99k stars 3.41k forks source link

Find less file path match error in npm package #4220

Open treeFuck opened 10 months ago

treeFuck commented 10 months ago

To reproduce:

The code structure is like this:

my project depends on lessPkg1@1.0.0 and lessPkg2 lessPkg2 depends on lessPkg1@2.0.0

When I try to use webpack to build my project, I found that when the lessPkg2 looks for lessPkg1@2.0.0, it will match lessPkg1@1.0.0

Breakpoint debugging webpack, I found the loadFile function in this file(node_modules/less/lib/less-node/file-manager.js),It will only match two paths:

As a result, lessPkg2 cannot find lessPkg1@2.0.0 under its own node_modules, but can only find lessPkg1@1.0.0 under node_modules of my project。

Expected behavior: I hope that when a less file in npm package is looking for a less file in another npm package, it will first search in its own node_modules directory. If it cannot be found,it will search in the parent directory until it matches up to the root path of the project.

When I debug vite@4.2.1 source code, I found the same error, But it has been fixed in this issue

When vite is looking for module dependencies, it will recurse upwards to the node_modules directory under the directory, see the code here

I think there should be a consistent ability here.

Environment information:

other English is not good, use translation software to write, forgive me.