在运行Grunt任务时,会出现以下错误。
Running "connect:client" (connect) task
Warning: root path must be a string Use --force to continue.
TypeError: root path must be a string
at Function.serveStatic (/Users/marif/Dev/JavaScript/JavaScript-Boilerplate/node_modules/grunt-contrib-connect/node_modules/connect/node_modules/serve-static/index.js:43:11)
at Object.livereloadMiddleware (/Users/marif/Dev/JavaScript/JavaScript-Boilerplate/GruntFile.js:25:23)
at Object.<anonymous> (/Users/marif/Dev/JavaScript/JavaScript-Boilerplate/node_modules/grunt-contrib-connect/tasks/connect.js:110:41)
at Object.<anonymous> (/Users/marif/Dev/JavaScript/JavaScript-Boilerplate/node_modules/grunt/lib/grunt/task.js:264:15)
at Object.thisTask.fn (/Users/marif/Dev/JavaScript/JavaScript-Boilerplate/node_modules/grunt/lib/grunt/task.js:82:16)
at Object.<anonymous> (/Users/marif/Dev/JavaScript/JavaScript-Boilerplate/node_modules/grunt/lib/util/task.js:301:30)
at Task.runTaskFn (/Users/marif/Dev/JavaScript/JavaScript-Boilerplate/node_modules/grunt/lib/util/task.js:251:24)
at Task.<anonymous> (/Users/marif/Dev/JavaScript/JavaScript-Boilerplate/node_modules/grunt/lib/util/task.js:300:12)
at /Users/marif/Dev/JavaScript/JavaScript-Boilerplate/node_modules/grunt/lib/util/task.js:227:11
at process._tickCallback (node.js:355:11)
Grunt任务如下:
connect: {
client: {
options: {
// The server's port, and the folder to serve from:
// Ex: 'localhost:9000' would serve up 'client/index.html'
port: 9000,
// change this to '0.0.0.0' to access the server from outside
hostname: 'localhost',
base: '<%= jsb.app %>',
// Custom middleware for the HTTP server:
// The injected JavaScript reloads the page.
middleware: livereloadMiddleware
}
}
}
尝试卸载并安装npm软件包但到目前为止没有运气。
有人可以指出,我到底错过了什么?
答案 0 :(得分:0)
我的中间件函数中的options.base
似乎变成了一个数组,因为我已将npm包grunt-contrib-connect
更新为最新的0.10.1
。
必须更改代码段:
connect.static(options.base),
// Make empty directories browsable.
connect.directory(options.base)
它必须是一个数组,它应该开始工作:
connect.static(options.base[0]),
// Make empty directories browsable.
connect.directory(options.base[0])
希望它也可以帮助别人!