javascript grunt serve:并发:服务器由于警告而中止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24382098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 02:41:23  来源:igfitidea点击:

grunt serve: concurrent:server aborts due to warnings

javascriptnode.jsangularjsgruntjs

提问by 23tux

suddenly my projects stops working with grunt. Unfortunately, I haven't committed my changes for a while into git, so I can't tell whats different.

突然间,我的项目停止使用 grunt。不幸的是,我有一段时间没有将我的更改提交到 git 中,所以我不知道有什么不同。

When I run grunt server --verbose, I get the following output (everything above ...passes with an OK):

当我运行时grunt server --verbose,我得到以下输出(上面的所有内容都...带有OK):

...
Running "wiredep" task

Running "wiredep:app" (wiredep) task
Verifying property wiredep.app exists in config...OK
Files: app/index.html
Verifying property wiredep.app.src exists in config...OK

Running "wiredep:sass" (wiredep) task
Verifying property wiredep.sass exists in config...OK
Files: app/styles/analyzer.scss, app/styles/colors.scss, app/styles/login.scss, app/styles/main.scss, app/styles/shared.scss, app/styles/styles.scss, app/styles/tagsinput.scss
Verifying property wiredep.sass.src exists in config...OK

Running "concurrent:server" (concurrent) task
Verifying property concurrent.server exists in config...OK
Files: [no src] -> server
Options: limit=2
    Warning:  Use --force to continue.

        Aborted due to warnings.


Execution Time (2014-06-24 08:34:05 UTC)
loading tasks        8ms  0%
serve                2ms  0%
clean:server        10ms  0%
wiredep:app        242ms  ▇▇▇▇▇▇▇ 4%
wiredep:sass        17ms  0%
concurrent:server   5.3s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 95%
Total 5.6s

So, grunt aborts when trying to execute the task concurrent:server. Inside this task, the compass:servertask is executed (see the Gruntfile.jsbelow). So, it must have something todo with compass, but I'm not sure if this line Files: [no src] -> servercould give more hints to the problem.

因此, grunt 在尝试执行任务时中止concurrent:server。在这个任务中,compass:server任务被执行(见Gruntfile.js下文)。所以,它一定与指南针有关,但我不确定这条线Files: [no src] -> server是否可以为问题提供更多提示。

This is my Gruntfile.js:

这是我的Gruntfile.js

// Generated on 2014-06-16 using generator-angular 0.9.0-1
'use strict';

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'

module.exports = function (grunt) {

  // Load grunt tasks automatically
  require('load-grunt-tasks')(grunt);

  // Time how long tasks take. Can help when optimizing build times
  require('time-grunt')(grunt);

  // Configurable paths for the application
  var appConfig = {
    app: require('./bower.json').appPath || 'app',
    dist: 'dist'
  };

  // Define the configuration for all the tasks
  grunt.initConfig({

    // Project settings
    yeoman: appConfig,

    // Watches files for changes and runs tasks based on the changed files
    watch: {
      bower: {
        files: ['bower.json'],
        tasks: ['wiredep']
      },
      js: {
        files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],
        tasks: [],
        options: {
          livereload: '<%= connect.options.livereload %>'
        }
      },
      jsTest: {
        files: ['test/spec/{,*/}*.js'],
        tasks: ['newer:jshint:test', 'newer:jshint:all', 'karma']
      },
      compass: {
        files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
        tasks: ['compass:server', 'autoprefixer'],
        options: {
            spawn: false,
        }
      },
      gruntfile: {
        files: ['Gruntfile.js']
      },
      livereload: {
        options: {
          livereload: '<%= connect.options.livereload %>'
        },
        files: [
          '<%= yeoman.app %>/{,*/}*.html',
          '<%= yeoman.app %>/scripts/directives/**/*.html',
          '.tmp/styles/{,*/}*.css',
          '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
        ]
      }
    },

    // The actual grunt server settings
    connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'localhost',
        livereload: 35729
      },
      livereload: {
        options: {
          open: false,
          middleware: function (connect) {
            return [
              connect.static('.tmp'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
              connect.static(appConfig.app)
            ];
          }
        }
      },
      test: {
        options: {
          port: 9001,
          middleware: function (connect) {
            return [
              connect.static('.tmp'),
              connect.static('test'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
              connect.static(appConfig.app)
            ];
          }
        }
      },
      dist: {
        options: {
          open: false,
          base: '<%= yeoman.dist %>'
        }
      }
    },

    // Make sure code styles are up to par and there are no obvious mistakes
    jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      all: {
        src: [
          'Gruntfile.js',
          '<%= yeoman.app %>/scripts/{,*/}*.js'
        ]
      },
      test: {
        options: {
          jshintrc: 'test/.jshintrc'
        },
        src: ['test/spec/{,*/}*.js']
      }
    },

    // Empties folders to start fresh
    clean: {
      dist: {
        files: [{
          dot: true,
          src: [
            '.tmp',
            '<%= yeoman.dist %>/{,*/}*',
            '!<%= yeoman.dist %>/.git*'
          ]
        }]
      },
      server: '.tmp'
    },

    // Add vendor prefixed styles
    autoprefixer: {
      options: {
        browsers: ['last 1 version']
      },
      dist: {
        files: [{
          expand: true,
          cwd: '.tmp/styles/',
          src: '{,*/}*.css',
          dest: '.tmp/styles/'
        }]
      }
    },

    // Automatically inject Bower components into the app
    wiredep: {
      app: {
        src: ['<%= yeoman.app %>/index.html'],
        ignorePath: new RegExp('^<%= yeoman.app %>/|../')
      },
      sass: {
        src: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
        ignorePath: /(\.\.\/){1,2}bower_components\//
      }
    },

    // Compiles Sass to CSS and generates necessary files if requested
    compass: {
      options: {
        sassDir: '<%= yeoman.app %>/styles',
        cssDir: '.tmp/styles',
        generatedImagesDir: '.tmp/images/generated',
        imagesDir: '<%= yeoman.app %>/images',
        javascriptsDir: '<%= yeoman.app %>/scripts',
        fontsDir: '<%= yeoman.app %>/styles/fonts',
        importPath: './bower_components',
        httpImagesPath: '/images',
        httpGeneratedImagesPath: '/images/generated',
        httpFontsPath: '/styles/fonts',
        relativeAssets: false,
        assetCacheBuster: false,
        raw: 'Sass::Script::Number.precision = 10\n'
      },
      dist: {
        options: {
          generatedImagesDir: '<%= yeoman.dist %>/images/generated'
        }
      },
      server: {
        options: {
          debugInfo: true
        }
      }
    },

    // Renames files for browser caching purposes
    filerev: {
      dist: {
        src: [
          '<%= yeoman.dist %>/scripts/{,*/}*.js',
          '<%= yeoman.dist %>/styles/{,*/}*.css',
          '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
          '<%= yeoman.dist %>/styles/fonts/*'
        ]
      }
    },

    // Reads HTML for usemin blocks to enable smart builds that automatically
    // concat, minify and revision files. Creates configurations in memory so
    // additional tasks can operate on them
    useminPrepare: {
      html: '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>',
        flow: {
          html: {
            steps: {
              js: ['concat', 'uglifyjs'],
              css: ['cssmin']
            },
            post: {}
          }
        }
      }
    },

    // Performs rewrites based on filerev and the useminPrepare configuration
    usemin: {
      html: ['<%= yeoman.dist %>/{,*/}*.html'],
      css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
      options: {
        assetsDirs: ['<%= yeoman.dist %>','<%= yeoman.dist %>/images']
      }
    },

    // The following *-min tasks will produce minified files in the dist folder
    // By default, your `index.html`'s <!-- Usemin block --> will take care of
    // minification. These next options are pre-configured if you do not wish
    // to use the Usemin blocks.
    // cssmin: {
    //   dist: {
    //     files: {
    //       '<%= yeoman.dist %>/styles/main.css': [
    //         '.tmp/styles/{,*/}*.css'
    //       ]
    //     }
    //   }
    // },
    // uglify: {
    //   dist: {
    //     files: {
    //       '<%= yeoman.dist %>/scripts/scripts.js': [
    //         '<%= yeoman.dist %>/scripts/scripts.js'
    //       ]
    //     }
    //   }
    // },
    // concat: {
    //   dist: {}
    // },

    imagemin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.{png,jpg,jpeg,gif}',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

    svgmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.svg',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

    htmlmin: {
      dist: {
        options: {
          collapseWhitespace: true,
          conservativeCollapse: true,
          collapseBooleanAttributes: true,
          removeCommentsFromCDATA: true,
          removeOptionalTags: true
        },
        files: [{
          expand: true,
          cwd: '<%= yeoman.dist %>',
          src: ['*.html', 'views/{,*/}*.html'],
          dest: '<%= yeoman.dist %>'
        }]
      }
    },

    // ngmin tries to make the code safe for minification automatically by
    // using the Angular long form for dependency injection. It doesn't work on
    // things like resolve or inject so those have to be done manually.
    ngmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '.tmp/concat/scripts',
          src: '*.js',
          dest: '.tmp/concat/scripts'
        }]
      }
    },

    // Replace Google CDN references
    cdnify: {
      dist: {
        html: ['<%= yeoman.dist %>/*.html']
      }
    },

    // Copies remaining files to places other tasks can use
    copy: {
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= yeoman.app %>',
          dest: '<%= yeoman.dist %>',
          src: [
            '*.{ico,png,txt}',
            '.htaccess',
            '*.html',
            'views/{,*/}*.html',
            'images/{,*/}*.{webp}',
            'fonts/*'
          ]
        }, {
          expand: true,
          cwd: '.tmp/images',
          dest: '<%= yeoman.dist %>/images',
          src: ['generated/*']
        }, {
          expand: true,
          cwd: '.',
          src: 'bower_components/bootstrap-sass-official/vendor/assets/fonts/bootstrap/*',
          dest: '<%= yeoman.dist %>'
        }]
      },
      styles: {
        expand: true,
        cwd: '<%= yeoman.app %>/styles',
        dest: '.tmp/styles/',
        src: '{,*/}*.css'
      }
    },

    // Run some tasks in parallel to speed up the build process
    concurrent: {
      server: [
        'compass:server'
      ],
      test: [
        'compass'
      ],
      dist: [
        'compass:dist',
        'imagemin',
        'svgmin'
      ]
    },

    // Test settings
    karma: {
      unit: {
        configFile: 'test/karma.conf.js',
        singleRun: false
      }
    }
  });


  grunt.loadNpmTasks('grunt-sass');

  grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
    if (target === 'dist') {
      return grunt.task.run(['build', 'connect:dist:keepalive']);
    }
    grunt.task.run([
      'clean:server',
      'wiredep',
      'concurrent:server',
      'autoprefixer',
      'connect:livereload',
      'watch'
    ]);
  });

  grunt.registerTask('server', 'DEPRECATED TASK. Use the "serve" task instead', function (target) {
    grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
    grunt.task.run(['serve:' + target]);
  });

  grunt.registerTask('test', [
    'clean:server',
    'autoprefixer',
    'connect:test',
    'karma'
  ]);

  grunt.registerTask('build', [
    'clean:dist',
    'wiredep',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'ngmin',
    'copy:dist',
    'cdnify',
    'cssmin',
    'uglify',
    'filerev',
    'usemin',
    'htmlmin'
  ]);

  grunt.registerTask('default', [
    'newer:jshint',
    'test',
    'build'
  ]);
};

I generated the project with the yo angular generator. And this is my environment:

我用 yo angular generator 生成了这个项目。这是我的环境:

  • node -v: v0.10.25
  • ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
  • yo -v: 1.1.2
  • gem list:

    * LOCAL GEMS *

    bigdecimal (1.2.4) bundler (1.6.2) bundler-unload (1.0.2) chunky_png (1.3.1) compass (0.12.6) executable-hooks (1.3.1) fssm (0.2.10) gem-wrappers (1.2.4) io-console (0.4.2) json (1.8.1) minitest (4.7.5) psych (2.0.5) rake (10.1.0) rdoc (4.1.0) rubygems-bundler (1.4.3) rvm (1.11.3.9) sass (3.3.8, 3.2.19) test-unit (2.1.2.0)

  • grunt --verison: grunt-cli v0.1.13, grunt v0.4.5

  • Mac OS X 10.9
  • node -v: v0.10.25
  • ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
  • yo -v: 1.1.2
  • gem list:

    * 本地宝石 *

    bigdecimal (1.2.4) bundler (1.6.2) bundler-unload (1.0.2) chunky_png (1.3.1) compass (0.12.6) executable-hooks (1.3.1) fssm (0.2.10) gem-wrappers ( 1.2.4) io-console (0.4.2) json (1.8.1) minitest (4.7.5) psych (2.0.5) rake (10.1.0) rdoc (4.1.0) ruby​​gems-bundler (1.4.3) rvm (1.11.3.9) sass (3.3.8, 3.2.19) 测试单元 (2.1.2.0)

  • grunt --verison: grunt-cli v0.1.13, grunt v0.4.5

  • Mac OS X 10.9

This is my package.json:

这是我的package.json

{
  "name": "project1",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "grunt": "^0.4.1",
    "grunt-autoprefixer": "^0.7.3",
    "grunt-concurrent": "^0.5.0",
    "grunt-contrib-clean": "^0.5.0",
    "grunt-contrib-coffee": "^0.10.1",
    "grunt-contrib-compass": "~0.8.0",
    "grunt-contrib-concat": "^0.4.0",
    "grunt-contrib-connect": "^0.7.1",
    "grunt-contrib-copy": "^0.5.0",
    "grunt-contrib-cssmin": "^0.9.0",
    "grunt-contrib-htmlmin": "^0.3.0",
    "grunt-contrib-imagemin": "^0.7.0",
    "grunt-contrib-jshint": "^0.10.0",
    "grunt-contrib-uglify": "^0.4.0",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-filerev": "^0.2.1",
    "grunt-google-cdn": "^0.4.0",
    "grunt-newer": "^0.7.0",
    "grunt-ngmin": "^0.0.3",
    "grunt-svgmin": "^0.4.0",
    "grunt-usemin": "^2.1.1",
    "grunt-wiredep": "^1.7.0",
    "jshint-stylish": "^0.2.0",
    "load-grunt-tasks": "^0.4.0",
    "time-grunt": "^0.3.1",
    "coffee-script": "~1.7.1",
    "grunt-karma": "~0.8.3",
    "karma-phantomjs-launcher": "~0.1.4",
    "karma": "~0.12.16",
    "karma-jasmine": "~0.1.5",
    "karma-coffee-preprocessor": "~0.2.1",
    "karma-chrome-launcher": "~0.1.4",
    "karma-script-launcher": "~0.1.0",
    "karma-firefox-launcher": "~0.1.3",
    "karma-safari-launcher": "~0.1.1",
    "karma-ng-html2js-preprocessor": "~0.1.0",
    "karma-junit-reporter": "~0.2.2",
    "grunt-ng-constant": "~0.5.0",
    "grunt-bowercopy": "~1.0.1",
    "karma-coverage": "~0.2.4",
    "grunt-protractor-runner": "~1.0.0",
    "karma-jasmine-given": "~0.1.1",
    "grunt-sass": "~0.13.1"
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "test": "grunt test"
  }
}

And this is my bower.json:

这是我的bower.json

{
  "name": "project1",
  "version": "0.0.0",
  "dependencies": {
    "angular": "1.3.0-beta.11",
    "json3": "~3.3.1",
    "es5-shim": "~3.1.0",
    "jquery": "~1.11.1",
    "bootstrap-sass-official": "~3.1.1",
    "bootstrap": "~3.1.1",
    "angular-resource": "1.3.0-beta.11",
    "angular-cookies": "1.3.0-beta.11",
    "angular-sanitize": "1.3.0-beta.11",
    "angular-animate": "1.3.0-beta.11",
    "angular-touch": "1.3.0-beta.11",
    "angular-route": "1.3.0-beta.11",
    "font-awesome": "~4.1",
    "underscore": "~1.6.0"
  },
  "devDependencies": {
    "angular-mocks": "1.3.0-beta.11",
    "angular-scenario": "1.3.0-beta.11"
  },
  "appPath": "app"
}

回答by 23tux

Stupid me!

愚蠢的我!

For anybody encountering the same issue:

对于遇到相同问题的任何人:

I had some import errors in my SCSS files. During the live reload of grunt, it would tell you that there is something wrong. But during the startup of grunt serveit just breaks and tells you nothing. So, check your imports and syntax of your SCSS files.

我的 SCSS 文件中有一些导入错误。在 grunt 的实时重新加载期间,它会告诉您有问题。但是在启动过程中grunt serve它只是中断并且什么也不告诉你。因此,请检查您的 SCSS 文件的导入和语法。

回答by sammysounder

It's import in SCSS files. Try

它在 SCSS 文件中导入。尝试

grunt serve --force

This may force the build process to continue even though your SCSS fails to compile. The end result is you'll start the grunt server and it'll tell you exactly where the build process failed.

即使您的 SCSS 无法编译,这也可能会强制构建过程继续。最终结果是您将启动 grunt 服务器,它会准确地告诉您构建过程失败的位置。

回答by meeming

Actually my scss has no grammar faults,it only because I installed compass by npm -g, it needs to be installed by ruby gem!

其实我的scss没有语法错误,只是因为我用npm -g安装了compass,需要用ruby gem安装!

gem install compass

resolved my issue perfectly!

完美解决了我的问题!

回答by user2520890

I am not an expert but I find that once the local server is running it will allow lint errors in scss or whatever, then once you stop the server and try to restart it will give this error until you fix the scss errors. You can use grunt check and then just resolve them and try again. 9/10 this is why my server wont restart.

我不是专家,但我发现一旦本地服务器运行,它将允许 scss 或其他内容中的 lint 错误,然后一旦您停止服务器并尝试重新启动它就会出现此错误,直到您修复 scss 错误。您可以使用 grunt 检查,然后解决它们并重试。9/10 这就是我的服务器无法重启的原因。