Skip to content

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

Open

Description

@YourWildDad

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:

Activity

  1. changed the title [-]Can't use package.json `imports` property to import subpath module.[/-] [+]Can't use package.json property `imports` to import subpath module.[/+] on Apr 20, 2022
  2. RUSHIM24 commented on Apr 10, 2023

    @RUSHIM24

    Hello , I am new to open source , I want to work on this issue can you please guide me on how I can get started?

  3. matthew-dean commented on Apr 10, 2023

    @matthew-dean
    Member
  4. RUSHIM24 commented on Apr 14, 2023

    @RUSHIM24

    Hello , I found the bug and made the changes in local repository as well as when I ran the test , all test worked fine, My question is, how do I ensure that the error : #style/mixins' wasn't found , is resolved or not?

  5. Cyddharth-Gupta commented on Jul 10, 2023

    @Cyddharth-Gupta

    @matthew-dean can I be assigned this issue?

  6. MUNJETIJAYANTHKRISHNA commented on Oct 20, 2025

    @MUNJETIJAYANTHKRISHNA

    I’ve gone through the issue and the related discussion. I’d like to work on improving support for resolving subpath imports using the package.json imports field.

    From what I understand, the main problem is that LESS tries to resolve the path before Webpack’s resolver or the FileManager handles it. My plan is to:

    1. Investigate how the FileManager handles path resolution at file-manager.js#L62.
    2. Add a check to allow subpath imports like #style/* to be resolved through Node’s imports map or Webpack resolver before throwing the “wasn’t found” error.
    3. Test the fix with a package.json that includes a custom imports field to verify resolution works as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions