Grunt file not building CSS file (SASS): Errno::ENOENT: No such file or directory # rb_sysopen - undefined - visual-studio

I have a Grunt file, that should build my CSS file. When I run the task in the Task Runner (Visual Studio), I get below error:
Running "sass:dist" (sass) task Errno::ENOENT: No such file or
directory # rb_sysopen - undefined Use --trace for backtrace.
Warning: Exited with error code 1 Use --force to continue. Aborted
due to warnings. Process terminated with code 6.
My Grunt file:
module.exports = function (grunt) {
grunt.initConfig({
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'/css/styles.css': '/css/sass/styles.scss'
}
}
},
watch: {
css: {
files: ['css/sass/*.scss'],
tasks: ['sass'],
options: {
livereload: true,
},
},
},
});
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
};
My directory:
I use Visual Studio 2017 and have a standard ASP.NET Core project.
I read a bit, and it seems it could be the SASS cache. However, when I run the rm .sass-cache/ -R command, I get
rm: cannot remove '.sass-cache/': No such file or directory
Any ideas?

My guess is that there's confusion over what path you're starting from. I believe grunt runs from the project root, and wwwroot is a subfolder of that. Either prefix your paths in the grunt file with wwwroot/, or consider moving your .scss files out of wwwroot entirely, since they aren't intended to be served. They can go under the project root, and you can have grunt copy the .css outputs into wwwroot where they belong.

Related

Setup Laravel Mix with SASS and PostCSS critical CSS splitting

I want to setup Laravel Mix with mix.sass AND PostCss Critical CSS splitting. In the end I want two files: app.css and app-critical.css.
Unfortunately I can get this to work. One of the setups (webpack.mix.js) I did try:
mix
.js('templates/src/js/app.js', 'web/assets/dist/')
.js('templates/src/js/home.js', 'web/assets/dist/')
.extract(['vue','axios','lazysizes','svgxuse', 'fontfaceobserver'], 'web/assets/dist/vendor.js')
.sass('templates/src/scss/app.scss', 'web/assets/dist/')
.sourceMaps()
.options({
postCss: [
require('postcss-critical-css')({
preserve: false,
minify: false
})
]
})
.browserSync({
proxy: '127.0.0.1:8080',
files: [
'templates/**/*.twig',
'templates/src/js/**/*',
'templates/src/scss/**/*'
]
});
if (mix.inProduction()) {
console.log("In production");
mix.version();
}
When I run the script via 'npm run watch' I get an error:
10% building modules 0/1 modules 1 active ...ign-tools/templates/src/scss/app.scssWithout `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.
Also, my file is just copying over all the critical styling. The file grows bigger and bigger, expanding the duplicate code everytime the input SCSS/CSS-file changes.
I did try to set up Laravel Mix + mix.sass + one of the following plugins:
https://github.com/zgreen/postcss-critical-css
https://www.npmjs.com/package/postcss-critical-split
Without success :(
Anybody with a working setup or link to an example repository?
Thanks,
Teun

Heroku Error - Error: Failed to lookup view "index" in views directory

I keep getting this error when deploing to Heroku. Build process was succesfull but then I get this error. Can't figure out what is the problem and shouldn't path be src/server/views? Everything is working locally.
Error: Failed to lookup view "index" in views directory "src\server/views"
[web.1]:at /app/node_modules/express/lib/router/index.js:281:22
app[web.1]:at param (/app/node_modules/express/lib/router/index.js:354:14)
app[web.1]:at Function.render(/app/node_modules/express/lib/application.js:580:17)
app[web.1]:at param (/app/node_modules/express/lib/router/index.js:365:14)
app[web.1]:at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
app[web.1]:at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
I use webpack tu bundle my server side code and I use html-webpack-plugin to inject my index.ejs template from views folder to webpack bundle.
webpack.config.server.js
module.exports = {
devtool: 'source-map',
performance: {
hints: false
},
target: 'node',
node: {
__dirname: true,
__filename: true
},
entry: {
bundle: './src/server/prodServer.js'
},
output: {
path: path.join(buildPath, 'build'),
filename: '[name].js'
}
...
plugins: [
new HtmlWebpackPlugin({
template: 'ejs-loader!./src/server/views/index.ejs'
})
]
prodServer.js
app.set('view engine', 'ejs')
app.set('views', path.join(__dirname, 'views'))
folder structure
as you can see I have index.ejs inside views folder. prodServer is my server file and after webpack build I get bundle file and index.html.
In Heroku start script I run node ./src/build/bundle.js
It is because of how your __dirname is defined in Heroku. If you run heroku run bash and then run pwd you will see that your current working directory is /app, hence why /app is added in front of all your paths.
Try to play around with the command ls in your bash to see if your server folder is listed, and then with a cd server command see if the views file is there as well. Note that it is case sensitive, so most likely you had it defined in uppercase.
Also, note that it adds a src\ (with a backward slash instead of forward slash) to your src\server/views path, which could be from a wrong configuration in your webpack.config.server.js file.
I had the same problem and it was enough to change the script from package.json "start": "node app.js"
to
"start": "nodemon app.js"

Wiredep says Bower packages are not installed

I have the following wiredep task:
gulp.task('wiredep', function () {
log('Installing Bower Components in HTML files...)
return gulp
.src('./Views/Shared/_Layout.cshtml')
.pipe(wiredep({
bowerJson: require('./bower.json'),
directory: './bower_components/',
ignorePath: '../..'
}))
.pipe(gulp.dest('.'));
});
The goal is to convert the
<!-- bower:js -->
<!-- endbower -->
to actual JavaScripts as specified in my bower.json:
{
"name": "ASP.NET",
"private": true,
"dependencies": {
"bootstrap": "3.0.0",
"hammer.js": "2.0.4",
"jquery": "2.1.4",
"knockout": "3.3.0"
}
}
When I run the task I get the following output:
[15:53:06] Starting 'wiredep'...
[15:53:06] Installing Bower Components in HTML files...
events.js:72
throw er; // Unhandled 'error' event
^
Error: Error: bootstrap is not installed. Try running `bower install` or remove the component from your bower.json file
I do see the packages in wwwroot/lib, so I think Bower is actually installing it.
Can anyone help me solve this?
this part of your script:
directory: './bower_components/',
is using the wrong path /bower_components/ is the default install folder for bower components (actually in beta 4 VS 2015 RC it used to put files there) but in the latest VS project template there is a file .bowerrc in the root of the app that tells it to put bower components under wwwroot/lib instead of the default folder name. so directory needs to be ./wwwroot/lib/' I think.

Gulp watch sass causes terminal to hang - is that the point?

So I just got my hands dirty with Gulp. I have never worked with Grunt, but it seems that Gulp is the new big thing. Everything seems to work fine. I have successfully compiled SCSS into CSS with the following gulpfile.js:
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var sass = require('gulp-sass');
var rename = require('gulp-rename');
// Compile Our Sass
gulp.task('sass', function() {
return gulp.src('./scss/*.scss')
.pipe(sass())
.pipe(gulp.dest('./css'));
});
// Rerun the task when a file changes
gulp.task('watch', function () {
gulp.watch('scss/**/*.scss', ['sass']);
});
// Default Task
gulp.task('default', ['sass', 'watch']);
Thing is: When I run Gulp default in the terminal it starts the script, but never ends it. I'm assuming this is the point, that in order for Gulp to watch my files - it has to keep running.
It's on standby with this:
[gulp] Running 'sass'...
[gulp] Finished 'sass' in 8.47 ms
If that's the case - how do I stop it from running without closing and reopening the Terminal? I'm sorry if this is simple but i have no clue when it comes to the Terminal.
gulp watch is designed to watch the file changes, it acts as a running process.
The README shows an example of its usage: gulp-watch
The command: Ctrl+C will stop the process.
Once started modifying any file in the watch directive will trigger the action in the reload. You currently do not have any action for your watch, this will trigger a action when the sass files change:
gulp.watch('./scss/**/*.scss', ['sass']);

How to organize sass files, so compass includes them in the right order

I'm building a single page app using the most recent yeoman build 1.0.0beta3 and compass 0.12.2
When starting compass:server I get lots of errors, but during dev time all seems to be ok in my browser. grunt build then does not fail, but builds improper CSS output, so that the layout in the browser is borken. Maybe that's all my fault, caused by a misunderstanding.
What I have is a main.sass file with all my includes:
// compass
#import 'compass'
#import 'compass/reset'
#import 'compass/css3'
... and so on
//custom includes in the right order
#import 'base/dimensions'
#import 'base/colors'
#import 'base/layout'
The file base/dimensions now defines:
// height of the footer
$footer-height: 50px
And (later) in base/layout I make use of that:
.content-bg
background-color: rgba(0, 0, 0, 0.05)
bottom: $footer-height
... and more
When starting the grunt and compass server now, I get the following error:
Running "compass:server" (compass) task
directory .tmp/styles/
create .tmp/styles/avendor_font-awesome.css
create .tmp/styles/base_colors.css
create .tmp/styles/base_dimensions.css
error app/styles/base_layout.sass (Line 23: Undefined variable: "$footer-height".)
And lots of similar errors. (The footer height is indeed ok during dev time.)
I do not know how to solve that problem, and I do not know either if this causes the improper CSS after a build run. But when I build by issuing grunt I see the same errors in the console.
I should mention, I made some changes to Gruntfile.js, so that .sass files are loaded from subdirectories of /styles also:
grunt.initConfig({
yeoman: yeomanConfig,
watch: {
coffee: {
files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'],
tasks: ['coffee:dist']
},
coffeeTest: {
files: ['test/spec/{,*/}*.coffee'],
tasks: ['coffee:test']
},
compass: {
**files: ['<%= yeoman.app %>/styles/{,**/}*.{scss,sass}'],**
tasks: ['compass']
},
livereload: {
files: [
'<%= yeoman.app %>/*.html',
'{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
**'{.tmp,<%= yeoman.app %>}/styles/{,**/}*.css',**
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,webp}'
],
tasks: ['livereload']
}
},
Can anyone enlighten me?
Regards
Felix
For everyone facing the same problem: The naming of the files does the trick. Every file that is to be included in you main.css like so:
#include 'base/colors'
has to be named:
_colors.sass
instead of:
colors.sass
in the base directory in that case. What I did as well, was renaming main.css to main.css.sass
Now everything works correctly and I learned another thing the hard way.

Resources