Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.less extension in @import is not optional in watch mode under some file structures #117

Open
filipesilva opened this issue Jan 4, 2021 · 1 comment · May be fixed by #160
Open

.less extension in @import is not optional in watch mode under some file structures #117

filipesilva opened this issue Jan 4, 2021 · 1 comment · May be fixed by #160

Comments

@filipesilva
Copy link

Which version are you using (less-watch-compiler --version to find out)? 1.14.6

Is the issue reproducible after updating to the latest version ( npm update less-watch-compiler)? yes

Describe the bug
The LESS docs say that the .less extension is optional on imports.

But less-watch-compiler will throw an exception when it encounters such imports under very specific circumstances:

  • less-watch-compiler is ran on watch mode
  • there's another file in a nested folder

To Reproduce
Steps to reproduce the behavior:

  1. My folder setup is
.
├── css
│   └── site.css
├── less
│   ├── bem
│   │   └── block
│   │       └── file.less
│   ├── color.less
│   └── site.less

The less/bem/block/file.less and less/color.less files are empty. The content of less/site.less is @import "color";.

  1. The command I ran is yarn less-watch-compiler less css site.less
  2. Something went wrong... What is it?

Actual behavior
less-watch-compiler throws an error:

~/s/repro (master|●7+2…) $ 
yarn less-watch-compiler less css site.less
yarn run v1.22.5
$ /home/filipesilva/sandbox/repro/node_modules/.bin/less-watch-compiler less css site.less
Watching directory for file changes.
internal/fs/utils.js:220
    throw err;
    ^

Error: ENOENT: no such file or directory, stat '/home/filipesilva/sandbox/repro/less/color'
    at Object.statSync (fs.js:915:3)
    at Object.findLessImportsInFile (/home/filipesilva/sandbox/repro/node_modules/less-watch-compiler/dist/lib/filesearch.js:13:20)
    at Object.fileWatcher (/home/filipesilva/sandbox/repro/node_modules/less-watch-compiler/dist/lib/lessWatchCompilerUtils.js:225:38)
    at /home/filipesilva/sandbox/repro/node_modules/less-watch-compiler/dist/lib/lessWatchCompilerUtils.js:86:40
    at /home/filipesilva/sandbox/repro/node_modules/less-watch-compiler/dist/lib/lessWatchCompilerUtils.js:67:27
    at FSReqCallback.oncomplete (fs.js:159:5) {
  errno: -2,
  syscall: 'stat',
  code: 'ENOENT',
  path: '/home/filipesilva/sandbox/repro/less/color'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected behavior
Should compile less files successfully.

Desktop (please complete the following information):

  • OS: Ubuntu 18.04.3 LTS

Additional context
Using the --run-once flag will make it compile sucessfully.

Using the @import "color.less"; will make it compile sucessfully.

Removing the less/bem/block folder and leaving behind an empty less/bem folder will also make it compile sucessfully.

mhnaeem pushed a commit to mhnaeem/deadsimple-less-watch-compiler that referenced this issue Nov 22, 2021
…ion throws ENOENT error

Fixing a bug where .less extension is not optional with some @import statements in certain directory
strcutures. This fix checks if the @import statement has an extension available, if an extension is
not provided we assume the default as .less, related to issue jonycheung#117

fix jonycheung#117
@mhnaeem mhnaeem linked a pull request Nov 23, 2021 that will close this issue
2 tasks
@mhnaeem
Copy link

mhnaeem commented Nov 23, 2021

I have been facing the same issue and the PR attached above fixed it for me. The basis for change was this line in LESS documentation

If it does not have an extension, .less will be appended and it will be included as a imported Less file.

Link: https://lesscss.org/features/#import-atrules-feature-file-extensions

@jonycheung Let me know if it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants