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

Relative paths should start from file location, not project root #33

Open
ericorruption opened this issue Sep 2, 2015 · 8 comments
Open

Comments

@ericorruption
Copy link

Hello,

I'm having an issue with relative paths. In a SCSS partial i'm declaring a background-image as url(../img/bg.jpg), however the plugin searches for this file at the root of the project (/Users/user/Sites/code/project-folder), not relative to the stylesheet path (should be /Users/user/Sites/code/project-folder/src/css - where my CSS is).

Stack trace is as follows:

message: 'ENOENT, no such file or directory \'/Users/user/Sites/code/img/bg.jpg\'',
stack: 'Error: ENOENT, no such file or directory \'/Users/user/Sites/code/img/bg.jpg\'
    at Error (native)
    at Object.fs.openSync (fs.js:500:18)
    at syncFileToBuffer (/Users/user/Sites/code/project-folder/node_modules/cssgrace/node_modules/image-size/lib/index.js:58:23)
    at module.exports (/Users/user/Sites/code/project-folder/node_modules/cssgrace/node_modules/image-size/lib/index.js:100:18)
    at imageSetMixin (/Users/user/Sites/code/project-folder/node_modules/cssgrace/lib/index.js:423:9)
    at /Users/user/Sites/code/project-folder/node_modules/cssgrace/lib/index.js:477:5
    at /Users/user/Sites/code/project-folder/node_modules/gulp-postcss/node_modules/postcss/lib/container.js:88:34
    at /Users/user/Sites/code/project-folder/node_modules/gulp-postcss/node_modules/postcss/lib/container.js:73:26
    at Rule.each (/Users/user/Sites/code/project-folder/node_modules/gulp-postcss/node_modules/postcss/lib/container.js:59:22)
    at Rule.walk (/Users/user/Sites/code/project-folder/node_modules/gulp-postcss/node_modules/postcss/lib/container.js:72:21)'
@jglover
Copy link

jglover commented Sep 30, 2015

I've also run into this issue, the code looks like it has an option called opts.from but I don't know how to pass that in to the postcss CLI?

@ghost
Copy link

ghost commented Oct 1, 2015

+1 Also having this problem

@machwatt
Copy link

+1

@yuezk
Copy link

yuezk commented Nov 11, 2015

I think this issue have been fixed in the new version 3.x, I changed the path resolve in the PR #39. Related code is here.

@ericorruption
Copy link
Author

Resolved indeed.

@DotCoyote
Copy link

Nope, sincerely not, now it uses the path from the source-file:

/ css
/ img
  | image.png
/ src
  / scss
    | style.scss

style.scss:

.foo {
  background-image: url("../img/image.png");
}
Error: ENOENT: no such file or directory, open '/project/src/img/image.png'

@yuezk
Copy link

yuezk commented Dec 11, 2015

@CinKon , your source file is located in src/scss, and your built css is located in css folder. And now the plugin resolved path is relative to the source file path, so there should have a img folder under the src folder. I know your situation, and I think you should use some assets rebase plugins to handle this.

@PFanz
Copy link

PFanz commented Oct 21, 2016

+1 如果地址是非本地地址会报错

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