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

image-size, image-width, image-height doesn't work correctly #43

Closed
mdreizin opened this issue Apr 13, 2015 · 9 comments
Closed

image-size, image-width, image-height doesn't work correctly #43

mdreizin opened this issue Apr 13, 2015 · 9 comments

Comments

@mdreizin
Copy link

For instance, we have "sub/variables.less" which contains:

@img-width: image-width("../img/test.png");

And if try to import "~sub/variables.less" in other file (the resolve.root is set correctly) via:

@import (reference) "~sub/variables.less";

the "less-loader" will throws exception:

Module build failed: error evaluating function `image-width`: Cannot 'resolveSync' because the fileSystem is not sync. Use 'resolve'!
 @ <full-path-to-file>/sub/less/variables.less
@jhnns
Copy link
Member

jhnns commented Apr 16, 2015

Mhmmm that might be a limitation by webpack @sokra? Why is resolveSync not allowed?

@sokra
Copy link
Member

sokra commented Apr 20, 2015

webpack uses a async filesystem. You must use the async version of resolve.

@malykhinvi
Copy link

I have the same problem. Is there some workaround for this problem?

@jhnns
Copy link
Member

jhnns commented Apr 27, 2015

@sokra Shouldn't sync resolving be opt-in?

@sokra
Copy link
Member

sokra commented Apr 27, 2015

resolveSync can only be used with a sync filesystem. This never occurs with webpack. It only occurs with enhanced-require when you use a sync require. You must not use resolveSync in webpack.

The problem is that some parts of less.js don't use loadFile but only loadFileSync. Because you are not allowed to use sync io in a loader this breaks...

Either we use a uncool workaround with multiple less passes, or we fixed the occrences of loadFileSync in less.js (might require design changes).

@next0
Copy link
Contributor

next0 commented Oct 20, 2015

@sokra @jhnns, what about just use less.js FileManager insted of WebpackFileManager in this case? You can check this #58

@avivr
Copy link

avivr commented Nov 23, 2015

i'm having the same problem, trying to use image-height("../some/path/to/image.png") and get:

ERROR in ../~/css-loader!../~/less-loader!./less/main.less
Module build failed: error evaluating function `image-height`: Cannot 'resolveSync' because the fileSystem is not sync. Use 'resolve'!

can you please explain how to solve/workaround this, or what i'm doing wrong?
thanks!

@next0
Copy link
Contributor

next0 commented Nov 23, 2015

@avivr, as @sokra explain before, the less.js use only loadFileSync for functions like data-uri, image-size, image-width, image-height and etc. less-loader use custom WebpackFileManager as a plugin for less.js. The main issue, what webpack can't resolve sync file loads when running in async mode, but WebpackFileManager tells otherwise here. In case if supportsSync will be return false here in async mode, all sync file loads will be managed by native less.js and that error will be disappeared.
You can check my PR #58 , it should fix your issue.

@jhnns
Copy link
Member

jhnns commented Nov 25, 2015

Fix shipped with 2.2.2

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

No branches or pull requests

6 participants