Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Wrong path used for sourceMap #425

Closed
halfdan opened this issue Sep 21, 2014 · 12 comments
Closed

Wrong path used for sourceMap #425

halfdan opened this issue Sep 21, 2014 · 12 comments

Comments

@halfdan
Copy link

halfdan commented Sep 21, 2014

This commit seems to break the path used in sourceMap generation: fd6a201

We're using node-sass and grunt-sass for Ghost with the following setup:

// ### grunt-sass
// compile sass to css
sass: {
    compress: {
        options: {
            style: 'compressed',
            sourceMap: true
        },
        files: [
            { dest: 'core/client/assets/css/<%= pkg.name %>.min.css', src: 'core/client/assets/sass/screen.scss' },
            { dest: 'core/client/docs/dist/css/<%= pkg.name %>.min.css', src: 'core/client/assets/sass/screen.scss' }
        ]
    }
},

This however leads to the following error:

Running "sass:compress" (sass) task
Warning: ENOENT, open '/home/vagrant/code/Ghost/core/client/assets/css/core/client/assets/css/ghost.min.css.map' Use --force to continue.

The two lines used in sass.js generate that path:

dir = path.dirname(options.outFile); // Contains the full path to the outfile
sourceMapFile = path.resolve(dir, options.sourceMap); // sourceMap also contains the full path
halfdan added a commit to halfdan/node-sass that referenced this issue Sep 21, 2014
fixes sass#425
- Use path.basename
@am11
Copy link
Contributor

am11 commented Sep 21, 2014

I agree it's not straight forward. These changes are in accordance to those made in libsass.

It seems like, you need to provide two options: file (the abs. input filename with path) and outFile (the abs. target filename with path). If outFile is relative path, then libsass will resolve it from current working directory of grunt.

HTH.

@halfdan
Copy link
Author

halfdan commented Sep 21, 2014

Providing absolute paths to both dest/src seems to work. This should be documented $somewhere though :)

@spelufo
Copy link

spelufo commented Oct 12, 2014

Arrrg, getting this to work was painful. For future reference for those using node-sass from cli:

cd public/css && ../../node_modules/.bin/node-sass `pwd`/main.sass --source-comments map --source-map `pwd`/main.css.map -o `pwd`/main.css --watch --output-style compressed && cd ../..

Change to your directory structure accordingly. You must, for live css on chrome to work, cd into the directory with your styles first, in addition to using absolute paths. This is because the source maps url to which the comment in main.css points to is relative to the css directory.

There could be another way, but it was surprisingly difficult to find that one.

sindresorhus added a commit to sindresorhus/grunt-sass that referenced this issue Oct 16, 2014
only `sourceMap: true` works
simonexmachina added a commit to adopted-ember-addons/ember-cli-sass that referenced this issue Oct 21, 2014
@am11 am11 closed this as completed Oct 22, 2014
@spelufo
Copy link

spelufo commented Jan 14, 2015

Option parsing is still badly broken. You have examples for a thousand frameworks on the readme but your cli doesn't work.

$ ls static/
main.sass
$ node_modules/.bin/node-sass -r static/
{
  "status": 4,
  "message": "File to read not found or unreadable: static/",
  "code": 4
}
$ node_modules/.bin/node-sass -w static/main.sass -o static/main.css
Provide a Sass file to render

  Example
    node-sass --output-style compressed foobar.scss foobar.css
    cat foobar.scss | node-sass --output-style compressed > foobar.css

@am11
Copy link
Contributor

am11 commented Jan 15, 2015

@spelufo it is because you are not reading the docs carefully. -o option is for output directory.

You have examples for a thousand frameworks on the readme but your cli doesn't work.

Possibly.. This is an open source project and the philosophy that follow is: DIY

@glassdimly
Copy link
Contributor

cat sass/test.scss | node-sass > test.css
{
  "message": "file to import not found or unreadable: base\nCurrent dir: ",
  "column": 9,
  "line": 1,
  "file": "stdin",
  "status": 1
}

I can cat this file at the path normally... but node-sass is not reading from the pipe properly.

However, when I cd into the directory and cat the file it works properly.

@saper
Copy link
Member

saper commented Sep 24, 2015

@glassimly Where are your imports? in "sass"? If so, node-sass has no way to figure out it should look there - it just receives some bytes on standard input coming out of nowhere...

@glassdimly
Copy link
Contributor

@saper Thank you for your response. Isn't using cat with a pipe supposed to send text from standard input into node-sass for compilation? If I cat from within the directory that the file is located it works. Are you saying that node-sass is not reading from standard input?
To clarify, this works:

cat ./test.scss | node-sass

It just spits compiled css into the terminal. Isn't this how it's supposed to work?

node-sass --help
  Example
    cat foobar.scss | node-sass --output-style compressed > foobar.css

Thanks for helping me to clear up any misunderstanding I might have.

@saper
Copy link
Member

saper commented Sep 24, 2015

can you post your files (to gist.github.com or somewhere else convenient)? it is hard to guess what is going on...

@glassdimly
Copy link
Contributor

@saper Alright, I made a simple test to reproduce and thereby clarified things.

The actual bug/functionality here is that node-sass attempts to process @import relative to the current directory rather than from the directory of the file.

https://github.com/glassdimly/sass-bug-test

$ cat sasstest/test.scss | node-sass
{
  "message": "file to import not found or unreadable: test_import\nCurrent dir: ",
  "column": 9,
  "line": 6,
  "file": "stdin",
  "status": 1
}
$ cd sasstest/
$ cat test.scss | node-sass
.test .test-indent {
  font-weight: bold; }

.test_import {
  display: none; }

$ 

@saper
Copy link
Member

saper commented Sep 24, 2015

node-sass has no idea where test_import is.

If you really want, you can do this

cat sass/test.scss | ~/node_modules/node-sass/bin/node-sass --include-path sass

@glassdimly
Copy link
Contributor

@saper Thank you, that's really helpful, and fixes my problem.

Specifically:

cat sasstest/test.scss | node-sass --include-path sasstest/

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

Successfully merging a pull request may close this issue.

5 participants