less / less/less.js

inconsistent paths after `render` in `imports` on windows and linux

Open
#3,516 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug medium priority up-for-grabs
Dominant language
JavaScript
Stars
17k
Forks
3.4k
Avg merge
7h 42m
Merged PRs (30d)
26

Description

In less-loader we have custom FileManager plugin (https://github.com/webpack-contrib/less-loader/blob/master/src/utils.js#L27).

Algorithm (https://github.com/webpack-contrib/less-loader/blob/master/src/utils.js#L87):

  • try to load less file using built-in FileManager, if it is fail
  • try to load less file using webpack resolver

We have a code:

@import '~bootstrap-less-port/less/bootstrap.less'; // means load from `node_modules`

So less failed to resolve, and webpack resolver return C:\path\to\projects\node_modules\bootstrap-less-port\less\bootstrap.less

No problems on this step. Compilation works fine.

After render (https://github.com/webpack-contrib/less-loader/blob/master/src/index.js#L38), we adding all resolved files to watcher (for recompilation them after change). But imports on windows contains forward slashes:

[ 
  'C:/Users/IEUser/test-webpack-watch/node_modules/bootstrap-less-port/less/bootstrap.less',
  'C:\\Users\\IEUser\\test-webpack-watch\\node_modules\\bootstrap-less-port\\less\\_functions.less',
  // ...
]

On linux and macos no problems:

[
   '/home/evilebottnawi/IdeaProjects/test-webpack-watch/node_modules/bootstrap-less-port/less/bootstrap.less',
  '/home/evilebottnawi/IdeaProjects/test-webpack-watch/node_modules/bootstrap-less-port/less/_functions.less',
  // ...
]

If we change source code to:

@import '../node_modules/bootstrap-less-port/less/bootstrap.less';

We don't have this problem.

Ref: https://github.com/webpack-contrib/less-loader/issues/357

Reproducible repo:

https://github.com/Kukkimonsuta/test-webpack-watch

Just add console.log here https://github.com/webpack-contrib/less-loader/blob/master/src/index.js#L38

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 Windows and Linux behavior with the linked test-webpack-watch repository, then inspect src/utils.js around the custom FileManager algorithm and src/index.js around the render imports watcher setup. Compare the resolved paths recorded in imports and verify that the watcher receives consistent paths on both platforms.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.