Closed pocesar closed 7 years ago
I face the same issue with v4.5.0 on Windows 10. node-sass watch compiles for the first change then show error for the second change.
The same node-sass version run well on Mac OSX 10.11.6
I also have this issue on Windows 10 and node v6.9.5 when calling from node script
...
function style() {
sass.render({
file: path.join(path_style, 'main.sass')
}, function (err, result) {
if (err)
console.log(err);
else
fs.writeFileSync(
path.join(path_dist, `style.css`),
result.css
);
});
}
var style_watcher = chokidar.watch([
path.join(path_style, '/**/*.sass')
]);
style_watcher.on('change', style);
style_watcher.on('unlink', style);
In ./src/style
:
_Foo.sass
- OK@import Foo
to main.sass
and save- ALWAYS ERROR (shown below){ Error: File to read not found or unreadable: C:/Users/MJ420/Desktop/sass_test_project/src/style/main.sass
at Object.module.exports.renderSync (C:\Users\MJ420\Desktop\sass_test_project\node_modules\node-sass\lib\index.js:439:16)
at FSWatcher.style (C:\Users\MJ420\Desktop\sass_test_project\tools\tasks\main.js:158:27)
at emitTwo (events.js:106:13)
at FSWatcher.emit (events.js:191:7)
at FSWatcher.<anonymous> (C:\Users\MJ420\Desktop\sass_test_project\node_modules\chokidar\index.js:191:15)
at FSWatcher._emit (C:\Users\MJ420\Desktop\sass_test_project\node_modules\chokidar\index.js:233:5)
at FSWatcher.<anonymous> (C:\Users\MJ420\Desktop\sass_test_project\node_modules\chokidar\lib\nodefs-handler.js:263:16)
at FSReqWrap.oncomplete (fs.js:123:15)
status: 3,
message: 'File to read not found or unreadable: C:/Users/MJ420/Desktop/sass_test_project/src/style/main.sass',
formatted: 'Internal Error: File to read not found or unreadable: C:/Users/MJ420/Desktop/sass_test_project/src/style/main.sass\n' }
Have the same error when making the following steps:
ERROR:
{
"status": 3,
"message": "File to read not found or unreadable: F:/Rabbit/Site/src/app/assets/scss/test3",
"formatted": "Internal Error: File to read not found or unreadable: F:/Rabbit/Site/src/app/assets/scss/test3\n"
}
OS: Windows 10 Editor: Visual Studio Code NPM: v. 3.10.10 NODE: v. 6.10.0
Same issue on win10, node 7.7.4, visual studio code 1.10.2 It seems as if node-sass attempts to access the .sass file at the very moment it's locked by ide or something like that. So it happens no every time (1/3 of saves) and usually works on second save.
Same issue on win10, node 6.9.5 when using node-sass with --watch flag. Passed it using nodemon: "build-css": "node-sass src/ -o src/", "watch-css": "nodemon -e scss -x \"npm run build-css\""
Hi, I've the same error when run such npm script:
"scripts": {
"css:build": "node-sass src/scss/main.scss -o dist/css/ --output-style compressed",
"css:watch": "npm run css:build && npm run css:build -- -w",
"css": "npm run css:watch"
},
I'm using VS Code. After I tried to edit and save sccs file with notepad there are no any issues, all works fine. Who have troubles do you all also use VS Code?
Have the same error when making the following steps... { "status": 3, "message": "File to read not found or unreadable: d:/work/project_react/src/App.sass", "formatted": "Internal Error: File to read not found or unreadable: d:/work/project_react/src/App.sass\n" } "devDependencies": { "node-sass": "^4.5.2", "npm-run-all": "^4.0.2", "react-scripts": "0.9.5" }, "scripts": { "build-css": "node-sass src/ -o src/", "watch-css": "npm run build-css && node-sass src/ -o src/ --watch --recursive", "start-js": "react-scripts start", "start": "npm-run-all -p watch-css start-js", "build": "npm run build-css && react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }
OS: Windows 10 Editor: sublime text NODE: v4.4.7
This sounds like an issue with atomic saves. Make sure you disable atomic_save in Sublime.
You're also likely to have issues if you files are on a networked drive or container because of delays when writing the files.
This is a limitation of filesystem watchers and not something node-sass can do anything about.
grunt-watch works flawlessly, so it is a problem with node-sass
Have the same problem.
Could all the "me too" people say clearly which filesystem are they using on the affected drive?
Is it local NTFS drive? SMB share? Something virtualized?
If this is not a local NTFS drive? Can you reproduce the problem using local C: drive?
NTFS, local, primary
NTFS, local, secondary. I have to save the scss file twice, and then it will update my css file. This error occurs every time I save but only at the first save.
I am afraid this must be something with the way node watches file changes, not much we can do with node-sass :( it probably belongs to the node itself
I decided to take a closer look at this problem. I used Process Monitor to analyze what exactly happens after saving the file I mentioned earlier. Here are the results when error:
It seems that when a file is saved, sometimes VS Code does not keep up closing the file, while chokidar already triggered node-sass's job.
And this is a capture log when the file is processed without errors:
In both cases, only files from src
and dist
directories were captured.
Watcher code used for test::
// filename: development.js
var chokidar = require('chokidar')
var fs = require('fs')
var path = require('path')
var sass = require('node-sass')
var srcDir = path.resolve(__dirname, "../src")
var distDir = path.resolve(__dirname, "../dist")
chokidar.watch(path.join(srcDir, "**/*.scss")).on('all', (event, _path) => {
console.log("File changed: ", _path)
sass.render(
{
file: path.join(srcDir, "styles/main.scss"),
outFile: path.join(distDir, "main.css"),
sourceMap: true
},
function (err, result) {
if (err) {
console.log(err)
} else {
console.log(result)
fs.writeFile(path.join(distDir, "main.css"), result.css, (err) => {
if (err) {
console.log(err)
}
})
fs.writeFile(path.join(distDir, "main.css.map"), result.map, (err) => {
if (err) {
console.log(err)
}
})
}
}
)
})
I'm not familiar with c++ but it seems like this line is suspicious:
554: char* contents = read_file(abs_path);
I have not found function's read_file
documentation, but it seems when read locked file this return empty string.
IMO better idea is wait (with timeout) until file is unlocked and then read file.
I done another test.
Now node-sass call is wrapped in setTimeout
so it run with some delay, and I'm sure all other operations on this file have ended.
var chokidar = require('chokidar')
var fs = require('fs')
var path = require('path')
var sass = require('node-sass')
var srcDir = path.resolve(__dirname, "../src")
var distDir = path.resolve(__dirname, "../dist")
chokidar.watch(path.join(srcDir, "**/*.scss")).on('all', (event, _path) => {
console.log("File changed: ", _path)
setTimeout(() => {
sass.render(
{
file: path.join(srcDir, "styles/main.scss"),
outFile: path.join(distDir, "main.css"),
sourceMap: true
},
function (err, result) {
if (err) {
console.log(err)
} else {
fs.writeFile(path.join(distDir, "main.css"), result.css, (err) => {
if (err) {
console.log(err)
}
})
fs.writeFile(path.join(distDir, "main.css.map"), result.map, (err) => {
if (err) {
console.log(err)
}
})
}
}
)
}, 100)
})
Now I'm sure it's as I described in the previous comments
@sbfkcel this situation can occur because the VS Code and Node.js processes operate independently of each other. The problem lies with the lib-sass side, that does not check whether the file is currently readable.
In other transplers like LESS or Stylus, this problem probably is not occur (I haven't analyzed their code) because they are much slower and before they start reading from the file, the IDE is able to perform all operations on the file. Or they simply wait befere file is readable, but as I says, I didn't analyze their code.
@mikejav I think it should be like this. My solution now is to pass string-wise to node-sass to ensure the file is valid.
But there is still a problem, node-sass for some special character support may not be very friendly.
Actually I didn't solve this problem but I found a way to make it not interfere.In VS code you can simply replace a black space with a blank space using "ctrl+h" or by going to "edit" or manually and save the file then this problem doesn't appear.
I've created a PR that fix this problem: https://github.com/sass/node-sass/pull/2386
If want to try this fix, you can patch your node-sass local copy by replacing 'node_modules/node-sass/lib/render.js' with this version: https://github.com/marcosbozzani/node-sass/blob/bug-vscode-watch/lib/render.js
The diff is here: https://github.com/marcosbozzani/node-sass/commit/266861bf5761dcafd5d53d123264b965c861887c#diff-a485abf5b8f49de7f313d7799df3faf4
@marcosbozzani works form me on windows 10 and node-sass 4.9.0 version! Thanks a lot!
"node-sass": "^4.9.0", didn't worked for me, had to replace the file, only then it worked @MatteoPieroni @marcosbozzani
@marcosbozzani it worked! thx so much
works win10 node-sass 4.9.2 thx @marcosbozzani
Thanks a lot!
thanks mate @marcosbozzani ..it really works!
I'm using version 5.6.0 (npm - v sass) and it breaks sass. Am I doing something wrong?
@marcosbozzani Thanks for the PR but this doesn't seem to work for me on Windows 10, VSCode, using node-sass-chokidar. In fact, it 's so bad that it completely crahes my npm run. If some one's one chokidar and reading this, take a look at this solution instead: https://github.com/michaelwayman/node-sass-chokidar/issues/14#issuecomment-391320086
However, I would still like to say that looking at your code this isn't really a fix, more something that should serve as a temporary patch. It can't be that a solution consists of: trying a thousand times and if that not works, throwing an error.
@marcosbozzani Thank you so much. It works!
Thanks a ton @marcosbozzani !!
thanks!!!!!!!!!! @marcosbozzani
look at this site. it solve my problem wit this error https://shjhe.github.io/hexo/2018/07/30/File%20to%20read%20not%20found%20or%20unreadable/
Thanks, it works!! @marcosbozzani
Thank you @marcosbozzani it worked for me with node sass 4.11.0
npm -v
): 4.2.0node -v
): v7.5.0node -p process.versions
):node -p process.platform
): win32node -p process.arch
): x64node -p "require('node-sass').info"
):npm ls node-sass
):Randomly when using node-sass directly from command line (without gulp), it fails with the error:
the file exists all the time, the HDD is fine and healthy. it fails around 30% of the time, and I have to re-save the file for the watch to recompile. sometimes it fails 4-5 times in a row. the ownership of the files are fine, no symlinks are being used, if it matters, I'm using VSCode (but the problem happens with EmEditor as well)