less/less.js

Can't use package.json property `imports` to import subpath module.

Open

#3715 opened on Apr 20, 2022

View on GitHub
 (5 comments) (0 reactions) (0 assignees)JavaScript (16,977 stars) (3,517 forks)batch import
bugfeature requestgood first issueup-for-grabs

Description

My package.json :

{
    ...,
    "imports": {
        "#style/*": "./src/style/*"
    }
    ...
}

when i use less-loader to load less file like:

@import (refrence) "#style/mixins"

i got error like:

'#style/mixins' wasn't found. Tried - .less
      Error in D:\Development\xxx\index.module.less (line 2, column 0)

I think less throws an error before using the FileManager to resolve the file, making it impossible to use the webpack resolver to resolve the real path.

When I change the code to the following, everything works fine:

@import (refrence) "~#style/mixins"

My packages version is:

  • less@4.1.2
  • less-loader@10.2.0
  • webpack@5.68.0
  • enhanced-resolve@5.9.2

Contributor guide