less / less/less.js

Multiple scoped imports via (reference) fail

Open
#3,813 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
17k
Forks
3.4k
Avg merge
7h 42m
Merged PRs (30d)
26

Description

To reproduce:

.foo {
	@import (reference) "abc";
	.one {
		.two(); // defined in abc.less
	}
}

in another file

.bar {
	@import (reference) "abc";
	.three {
		.two(); // defined in abc.less
	}
}

Current behavior:

The second use of .two() fails with "NameError: .two is undefined in ..."

Expected behavior:

Both references should work.

Environment information:

I don't think the env matters here, but...

  • less version: 3 and 4
  • nodejs version: 18
  • operating system: Ubuntu 20.04

** Additional **

There is a workaround here by using:

	@import (multiple, reference) "abc";

The right behavior seems to me to be that the second reference should work because:

  1. The first reference is scoped, and therefor abc.less is not actually getting included twice, in the sense that duplicate css is being produced.
  2. It's a reference, and doesn't generate duplicate code anyway. Why not make the default 'multiple' to avoid the issue I had?
  3. Treating references in the manner suggested here seems to be the more typical way that compilers treat libraries.

If a change isn't made to the code, it seems like it may be worthwhile to put this info into the documentation somewhere.

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

Start with the reproduction showing two scoped (reference) imports of abc.less, and trace how import scope and duplicate-import handling are resolved. Add a regression test covering both .two() calls, then verify that both references compile successfully without requiring the (multiple, reference) workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.