Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Gulpfile.js:如何修复;TypeError:“输入错误”;“听众”;参数必须是函数";?_Javascript_Node.js_Gulp - Fatal编程技术网

Javascript Gulpfile.js:如何修复;TypeError:“输入错误”;“听众”;参数必须是函数";?

Javascript Gulpfile.js:如何修复;TypeError:“输入错误”;“听众”;参数必须是函数";?,javascript,node.js,gulp,Javascript,Node.js,Gulp,我开始设置我的开发环境,当我在终端上运行gulp时遇到了一些问题。 我不知道这个错误是从哪里来的。 以下是我的Gulpfile.js中的代码: var gulp = require('gulp'), sass = require('gulp-sass'), browserSync = require('browser-sync').create(), reload = browserSync.reload, php

我开始设置我的开发环境,当我在终端上运行gulp时遇到了一些问题。 我不知道这个错误是从哪里来的。 以下是我的Gulpfile.js中的代码:

var gulp        = require('gulp'),
    sass        = require('gulp-sass'),
    browserSync = require('browser-sync').create(),
    reload      = browserSync.reload,
    php         = require('gulp-connect-php'),
    source      = './sass',
    dest        = './css';

gulp.task('sass', function(){
  gulp.src(source+'/main.scss')
    .pipe(sass())
    .pipe(gulp.dest(dest))
    .on('error', onError)
    .pipe(reload({stream: true}));
});
// Watch php files
gulp.task('watch', function(){
    gulp.watch('blog/**/*.php');
    gulp.watch('admin/**/*.php');
    gulp.watch('portoflio/**/*.php');
    gulp.watch('functions/**/*.php');
    gulp.watch('templates/**/*.php');
    gulp.watch('index.php');
});

gulp.task('php', function() {
    php.server({
       base: './',
       port: 8010,
       keepalive: true
     });
});
gulp.task('browser-sync',['php'], function() {
    browserSync.init({
        proxy: 'http://localhost/username',
        files: ["**/*.php"],
        port: 8080,
        open: true,
        notify: false
    });
    gulp.watch(".sass/**/*.scss", ['sass']);
    // Watches for .php file changes
    gulp.watch("**/*.php").on("change", [reload]);
});
gulp.task('default', ['sass','browser-sync']);
function onError(err) {
  console.log(err);
  this.emit('end');
}
以下是终端中的错误:

    TypeError: "listener" argument must be a function
    at _addListener (events.js:216:11)
    at EventEmitter.addListener (events.js:276:10)
    at Gulp.<anonymous> (/Applications/MAMP/htdocs/username/gulpfile.js:43:28)
    at module.exports (/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at /Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/index.js:279:18
    at finish (/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
    at module.exports (/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:60:3)
    at Gulp.Orchestrator._runTask (/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
[Mon Jan  9 17:55:57 2017] Failed to listen on 127.0.0.1:8010 (reason: Address already in use)
TypeError:“listener”参数必须是函数
at_addListener(events.js:216:11)
在EventEmitter.addListener(events.js:276:10)
狼吞虎咽。(/Applications/MAMP/htdocs/username/gulpfile.js:43:28)
在module.exports(/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
位于Gulp.Orchestrator.\u runTask(/Applications/MAMP/htdocs/username/node\u modules/Gulp/node\u modules/Orchestrator/index.js:273:3)
运行步骤(/Applications/MAMP/htdocs/username/node\u modules/Gulp/node\u modules/Orchestrator/index.js:214:10)
at/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/index.js:279:18
完成时(/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
在module.exports(/Applications/MAMP/htdocs/username/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:60:3)
位于Gulp.Orchestrator.\u runTask(/Applications/MAMP/htdocs/username/node\u modules/Gulp/node\u modules/Orchestrator/index.js:273:3)
[2017年1月9日星期一17:55:57]未能在127.0.0.1:8010上收听(原因:地址已在使用中)

您的端口似乎已经在使用中

[Mon Jan 9 17:55:57 2017]未能在127.0.0.1:8010上侦听(原因:地址已在使用)

你能检查8010端口上运行的进程并关闭它吗

或者只是将端口更改为其他类似的端口

gulp.task('php', function() {
    php.server({
       base: './',
       port: 8020,
       keepalive: true
     });
});
如果这将起作用,那么您需要终止已经占用您端口的进程