grunt-contrib-connect | root path must be a string Use

647 views Asked by At

While running Grunt task, getting following error.

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 task is as given below:

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
        }
    }
}

Have tried to uninstall and install the npm package but no luck so far.

Can someone please point, what exactly I am missing here?

1

There are 1 answers

0
Mohammad Arif On

It seems like my options.base in my middleware function was becoming an array because I have updated the npm package grunt-contrib-connect to latest which is 0.10.1.

Have to change the snippet rather:

connect.static(options.base),
// Make empty directories browsable.
connect.directory(options.base)

It must be an Array and it should start working:

connect.static(options.base[0]),
// Make empty directories browsable.
connect.directory(options.base[0])

Hope it also helps someone!