less / less/less.js

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

Open
#3,715 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug feature request good first issue up-for-grabs
Dominant language
JavaScript
Stars
17k
Forks
3.4k
Avg merge
7h 42m
Merged PRs (30d)
26

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the package.json imports case with less@4.1.2, less-loader@10.2.0, webpack@5.68.0, and enhanced-resolve@5.9.2, comparing the failing #style/mixins import with the working ~#style/mixins form. Trace the LESS FileManager and webpack resolver entry points; done when the package imports mapping resolves without requiring the tilde prefix.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, webpack
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.