javascript - BrowserSync 在初始化时抛出 TypeError

标签 javascript node.js gulp browser-sync

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 问题:https://github.com/BrowserSync/browser-sync/issues/761

最佳答案

我在 Github 上回复了您已经因为我首先在那里找到了它。但也许人们也想在这里阅读它。我也遇到了同样的问题。

以下内容解决了我的问题:

注意第一行.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"
}

关于javascript - BrowserSync 在初始化时抛出 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31884226/

相关文章:

node.js - 命令行 - 更改路径并在同一行上运行 "npm install"

javascript - 提交时显示 div

javascript - 在 Stylus 和 Node.js 和 Express 中使用本 map 片是否可行?

node.js 和 postgresql 更新嵌套的 JSON 键

javascript - 如何准备 grunt 来使用 app.js 准备 dist 文件夹?

javascript - ESlint linting gulpfile.js

javascript - Navigator 和 AsyncStorage react native

javascript - jQuery 查找复选框并选中/取消选中它

javascript - HTML5 canvas ctx.fillText 不会换行?

javascript - 在没有 bundler 的情况下使用 Vue?