【问题标题】:what is the reason of " events.js:174 throw er; // Unhandled 'error' event " gulp error message? [duplicate]“ events.js:174 throw er; // Unhandled 'error' event” gulp 错误消息的原因是什么? [复制]
【发布时间】:2019-04-21 11:15:34
【问题描述】:

我正在尝试使用 jasmine 测试框架和 gulp 编写一个测试另一个功能代码的代码 但我是 Gulp 领域的新手,我遇到了以下问题 我的代码是:

/*eslint-env node */

const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
const eslint = require('gulp-eslint');
const jasmineBrowser = require('gulp-jasmine-browser');


gulp.task('default', ['styles', 'lint'], function() {
    gulp.watch('sass/**/*.scss', ['styles']);
    gulp.watch('js/**/*.js', ['lint']);

    browserSync.init({
        server: './'
    });
});

gulp.task('styles', function() {
    gulp
        .src('sass/**/*.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(
            autoprefixer({
                browsers: ['last 2 versions']
            })
        )
        .pipe(gulp.dest('./css'))
        .pipe(browserSync.stream());
});

gulp.task('lint', function() {
    return (
        gulp
            .src(['js/**/*.js'])
            // eslint() attaches the lint output to the eslint property
            // of the file object so it can be used by other modules.
            .pipe(eslint())
            // eslint.format() outputs the lint results to the console.
            // Alternatively use eslint.formatEach() (see Docs).
            .pipe(eslint.format())
            // To have the process exit with an error code (1) on
            // lint error, return the stream and pipe to failOnError last.
            .pipe(eslint.failOnError())
    );
});

gulp.task('tests', function() {
    return gulp
        .src('tests/spec/extraSpec.js')
        .pipe(jasmineBrowser.specRunner({ console: true }))

        .pipe(jasmineBrowser.headless({ driver: 'chrome' }));
});

当我在终端gulp tests 中执行以下命令时 我收到此错误消息

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: spawn C:\Users\atlas\Desktop\ud892\Lesson 2\node_modules\gulp-jasmine-browser\lib\runners\chrome_runner ENOENT

这个问题的原因是什么?我该如何解决? 考虑到我使用的是 windows7 和 ,我已经阅读了所有相关的 stackoverflow 帖子,但他们都没有答案。

【问题讨论】:

标签: gulp jasmine gulp-jasmine


【解决方案1】:

当您不使用 var/let/const 创建变量时,它会在全局范围内创建为全局变量,并且可以从代码中的任何位置访问。

如果您要使用strict mode,使用未初始化的变量(如您在上面所做的)将导致ReferenceError 错误,因为它还不存在。

【讨论】:

    猜你喜欢
    • 2019-12-14
    • 1970-01-01
    • 2019-08-21
    • 2019-09-16
    • 1970-01-01
    • 2017-06-23
    • 2018-07-23
    • 1970-01-01
    • 2019-01-27
    相关资源
    最近更新 更多