我正在创建一个小型Flask应用程序,并使用Gruntjs进行监视,连接和sass任务。当我运行" Grunt"命令,它会抛出一个错误:"致命错误:产生EACCES"并停止观看。
我已尝试按照上一个问题Grunt Watch Fatal error: listen EACCES and livereload中的建议向监视任务添加单个livereload选项,但这并未解决问题。
可能导致此错误的原因是什么?
Grunt日志:
Running "flaskServer" task
Starting the Flask server on port 5000
Running "concat:dist" (concat) task
File "./static/js/app.js" created.
Running "sass:dist" (sass) task
Fatal error: spawn EACCES
Gruntfile.js:
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
concat: {
options: {
separator: "\n",
},
dist: {
src: ['assets/**/*.js'],
dest: './static/js/app.js'
},
},
sass: {
dist: {
options: {
style: 'expanded'
},
files: [{
expand: true,
cwd: 'assets',
src: ['*.scss','!_*.scss'],
dest: './static/css',
ext: '.css'
}]
}
},
watch: {
javascripts: {
options: {
livereload: true
},
files: ['assets/js/*.js'],
tasks: ['concat']
},
styles: {
options: {
livereload: true
},
files: ['assets/**.scss'],
tasks: ['sass']
},
templates: {
options: {
livereload: true
},
files: ['templates/**/*.html'],
tasks: [] // empty for livereload
}
}
});
grunt.registerTask('flaskServer', 'runs the flask server', function() {
grunt.log.writeln('Starting the Flask server on port 5000');
var spawn = require('child_process').spawn;
var server = spawn('./run.sh');
server.stdout.on('data', function(data) {
grunt.log.writeln('FLASK LOG: ' + data);
});
process.on('exit', function() {
server.kill();
});
});
grunt.registerTask('dev', [
'concat',
'sass',
'watch'
]);
grunt.registerTask('server', [
'flaskServer'
]);
grunt.registerTask('default', [
'server',
'dev'
]);
};
文件结构:
/assets
/js
app.js
_normalize.scss
app.scss
/node_modules
/grunt
/grunt-contrib-concat
/grunt-contrib-copy
/grunt-contrib-sass
/grunt-congrib-watch
/load-grunt-tasks
/static
/css
app.css
/js
app.js
/templates
/layouts
base.html
/pages
404.html
index.html
app.py
Gruntfile.js
package.json
run.sh
答案 0 :(得分:0)
我能够通过在run.sh文件上启用用户可执行权限来解决此问题。
chmod u=rwx run.sh
答案 1 :(得分:0)
用sudo执行grunt命令,即sudo grunt
。