问题描述
初始化时,BrowserSync会引发TypeError
:
[12:02:53] TypeError: undefined is not a function
at Object.init (/Users/conti/dev/foodjournal-web/node_modules/browser-sync/lib/public/init.js:25:25)
at Gulp.<anonymous> (/Users/conti/dev/foodjournal-web/gulpfile.js:39:15)
at module.exports (/Users/conti/dev/foodjournal-web/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/Users/conti/dev/foodjournal-web/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/Users/conti/dev/foodjournal-web/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/Users/conti/dev/foodjournal-web/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
at Gulp.<anonymous> (/Users/conti/dev/foodjournal-web/node_modules/gulp/index.js:36:18)
at Gaze.<anonymous> (/Users/conti/dev/foodjournal-web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/index.js:18:14)
at Gaze.emit (events.js:110:17)
at Gaze.emit (/Users/conti/dev/foodjournal-web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:129:32)
指向browser-sync
gulp任务:
gulp.task('browser-sync', function () {
browserSync.init({
server: {
baseDir: "./public"
}
})
})
重新检查文档后,任??务已正确设置。 任何想法可能导致此类型错误吗?
打开github问题: :
1楼
我已经在上回答了您,因为我首先在那找到了它。 但是也许人们也想在这里阅读它。 我遇到过同样的问题。
以下解决了我的问题:
请注意第一行中.create之前的小注释
browserSync = require('browser-sync')#.create #call this wherever the heck you want
gulp = require('gulp-param')(require('gulp'), process.argv)
gulp.task 'default', ['browser-sync', 'watch'], ->
gulp.task 'browser-sync', ->
browserSync.init(
server: "./build")
gulp.task 'watch', ->
#something todo
我的用于版本检查的json文件:[...]
"devDependencies": {
"browser-sync": "^2.12.5",
"gulp": "^3.9.1",
"gulp-jshint": "^2.0.0",
"jshint": "^2.9.2",
"jshint-stylish": "^2.1.0"
}