-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Unable to get it working on Windows #793
Comments
Hello, As indicated in docs: https://github.com/sass/node-sass/#outfile, Node-Sass v2 brought this breaking change, where we don't write anything to filesystem, but let the API implementer do whatever they want with data. Why? because writing to filesystem is not the only use case. You may want to output the result to stream, store in db or do something else with it. In those cases, writing to file is an overhead and node-sass is supposed to act like an API. However, we do write to file with CLI usage. v3 example (API): require('node-sass').render({
data: '.selector { property: value }',
outFile: 'my/css/file/path/name.css',
sourceMap: true
}, function (err, result) {
if (err) {
throw err; // since err is instanceof Error
// or you can do something else with err and then return within if-block
// either way no need for else{}
}
console.log(result.css.toString());
// or you may want to
fs.writeFileSync(this.options.outFile, result.css, 'utf8');
// also note that result.css and result.map are of type Buffer,
// so you may need to use toString, see more details under example in README
// some functions like fs.writeFile*() and JSON.stringify(), accept buffers as is,
// so you do not need to cast it explicitly for those.
}); |
Thanks for the quick answer. So I guessed right about the need to write the result to a file ourselves. As said, giving a working example of such output for strangers to the Node.js ecosystem / API would be nice, to get your users quickly up and running. And the point about not being able to run the command line version on Windows remains. |
Ah, I finally went into bin/node-sass source, looking at line 208 (per the error message) and I see it is related to the source-map option. If I remove it from the command line, I get a CSS as expected! Problem half resolved (how do I get a source map, now?). |
OK, reading more of the source, I see that apparently the --source-map option expects a parameter (not obvious from the readme) which apparently can be a path, or "true". I don't close the issue as I feel it might be solved by adding some information to the documentation. |
Aside: |
At least this bit should be clear from the CLI usage help.. |
Feel free to send the pull request. |
"note that this part is not correct:" |
"Feel free to send the pull request." "would you like composing an example" |
:: this is cmd
C:\temp>notepad foo.scss
C:\temp>type foo.scss
test {
one: 1;
two: 2;
three: 3;
}
C:\temp>npm install node-sass@alpha
:: boring output
C:\temp>node_modules\.bin\node-sass --version
3.0.0-alpha.0
C:\temp>node_modules\.bin\node-sass foo.scss blah.css
Rendering Complete, saving .css file...
Wrote CSS to C:\temp\blah.css
C:\temp>type blah.css
test {
one: 1;
two: 2;
three: 3; } |
require('fs').renderFileSync(this.options.outFile, result.css, 'utf8') or var fs = require('fs');
fs.renderFileSync(this.options.outFile, result.css, 'utf8');
|
Meanwhile, based on your information, I did some searches, and ended with this script which seems to work:
|
Congrats! 😎 fs.writeFileSync(cssPath + "/playground.css", result.css.toString());
fs.writeFileSync(cssPath + "/playground.css.map", result.map.toString()); to fs.writeFileSync(cssPath + "/playground.css", result.css);
fs.writeFileSync(cssPath + "/playground.css.map", result.map);
// or
fs.writeFileSync(cssPath + "/playground.css", result.css, 'utf8');
fs.writeFileSync(cssPath + "/playground.css.map", result.map, 'utf8'); |
I confirm it works with your improved version. Thanks for the feedback, information and help (and patience!). Hey, at least, this thread can hopefully be useful to people hitting the same issues. 😄 My final version:
|
Glad to help! :) |
Either it is a true bug report against the library, or it is one against the documentation (the top readme)...
As you can see, I develop on Windows 7...
I am making a simple "skeleton" web application at https://github.com/PhiLhoSoft/Web-Playground
The idea is to experiment with a development stack, including Sass, of course.
I chose to skip Gulp / Grunt in favor of pure npm task running, so I have to learn the command line versions of the tools.
After reading the docs, I tried to generate a CSS file from my Sass one with the following script:
where the JS ile is as follows:
When I run it, it displays no errors:
Cool. Except I find no CSS file in the
src/main/css
folder. I thought theoutFile
parameter was used as destination... I also tried with an absolute path.That's where it is either a bug against the non-functioning outFile, or against the doc failing to indicate what this parameter is for... 😄
Ah, I see mentioned in the docs that maybe we should output the result.css and result.map to a file. If that's the way to go, I suggest to be a bit more explicit for people like me knowing nothing about Node.js scripting, and showing how it can be done.
After that, I tried another approach, with the following script:
but I get an error:
Argh.
I get the same error if instead of
node-sass
I putnode node_modules/node-sass/bin/node-sass
.If I do the script:
it works without problems. So the issue seems to be with the paths I give in the parameters.
If I put single quotes around the paths, I get the same error. If I put double quotes, node-sass complains: "Provide a Sass file to render".
I report the issue as I am starting to run out of ideas / workaround attempts... 😸
Thanks.
The text was updated successfully, but these errors were encountered: