Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.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 使用gulp服务静态文件时出现TypeError_Javascript_Node.js_Gulp_Connect - Fatal编程技术网

Javascript 使用gulp服务静态文件时出现TypeError

Javascript 使用gulp服务静态文件时出现TypeError,javascript,node.js,gulp,connect,Javascript,Node.js,Gulp,Connect,我在请求Gulp提供静态内容并加载Web服务器时遇到以下错误。我在看angularJS的专业书。 package.json和gulpfile都位于同一文件夹中 [21:30:44] Using gulpfile ~/Desktop/pro-angular2/gulpfile.js [21:30:44] Starting 'connect'... [21:30:44] 'connect' errored after 96 ms [21:30:44] TypeError: undefined is

我在请求Gulp提供静态内容并加载Web服务器时遇到以下错误。我在看angularJS的专业书。 package.json和gulpfile都位于同一文件夹中

[21:30:44] Using gulpfile ~/Desktop/pro-angular2/gulpfile.js
[21:30:44] Starting 'connect'...
[21:30:44] 'connect' errored after 96 ms
[21:30:44] TypeError: undefined is not a function
    at Gulp.<anonymous> (/home/kj/Desktop/pro-angular2/gulpfile.js:17:18)
    at module.exports (/home/kj/Desktop/pro-angular2/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/home/kj/Desktop/pro-angular2/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/home/kj/Desktop/pro-angular2/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/home/kj/Desktop/pro-angular2/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
    at node.js:814:3
和我的package.json文件

{
  "name": "pro-angular2",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "connect": "^3.4.0",
    "connect-livereload": "^0.5.4",
    "grunt": "^0.4.5",
    "grunt-contrib-connect": "^0.11.2",
    "grunt-contrib-jshint": "^0.11.3",
    "grunt-contrib-less": "^1.1.0",
    "grunt-contrib-watch": "^0.6.1",
    "gulp": "^3.9.0",
    "gulp-jshint": "^2.0.0",
    "gulp-less": "^3.0.5",
    "gulp-livereload": "^3.8.1",
    "gulp-load-plugins": "^1.1.0",
    "jshint": "^2.8.0",
    "load-grunt-tasks": "^3.3.0",
    "opn": "^3.0.3"
  }
}
这是树视图

.
|-- app
|   |-- app.js
|   |-- bower_components
|   |-- index.html
|   |-- main.css
|   `-- main.less
|-- bower.json
|-- gruntfile.js
|-- gulpfile.js
|-- node_modules
|   |-- connect
|   |-- connect-livereload
|   |-- grunt
|   |-- grunt-contrib-connect
|   |-- grunt-contrib-jshint
|   |-- grunt-contrib-less
|   |-- grunt-contrib-watch
|   |-- gulp
|   |-- gulp-jshint
|   |-- gulp-less
|   |-- gulp-livereload
|   |-- gulp-load-plugins
|   |-- jshint
|   |-- load-grunt-tasks
|   |-- opn
|   |-- serve-index
|   `-- serve-static
`-- package.json

服务器静态
服务索引
不再是
连接
的一部分。它们被提取为单独的模块。您包含了这些单独的模块,因此只需使用:

.use(serveStatic('app'))
.use(serveIndex('app'));

您使用connect而不是类似的东西有什么原因吗?看起来你所做的只是将
应用程序
目录作为一个静态站点提供服务。我不太确定如何使用http服务器,因为我刚刚开始学习服务器端javascript。。。上面的代码实际上是在我下面的教程中。。。你有我能读到的好资料吗?不是你现在正在做的教程中的内容。我建议使用http server或live server以及NPMSCcript,因此
npm安装http server——保存
(或live server),然后在package.json的“scripts”部分中,`“run”:“http server-p 9000./app”。这里不需要大口喝。但是,这与您正在运行的教程有很大不同。@Kunkka-看起来
connect
没有方法
serveStatic
。您是否尝试了应用程序。使用(serveStatic('./app'))
.use(serveStatic('app'))
.use(serveIndex('app'));