Search code examples
javascriptnode.jsgruntjsbowerbower-install

Can't install Bower components using Grunt - "Arguments to path.join must be strings"


I'm having issues installing Bower components using my Gruntfile.js. I can however install the Bower components fine using Bower command.

Installing Bower components using Bower command works fine.

bower install

I cannot however install Bower components using Grunt command

grunt bower:install

Hers's some details.

bower.json:

{
    "name": "test",
    "version": "0.0.2",
    "dependencies": {
        "angular": "latest",
        "bootstrap": "latest",
        "lodash": "latest",
        "font-awesome": "latest"
    },
    "devDependencies": {
        "angular-mocks": "latest"
    }
}

.bowerrc:

{
    "directory": "libs",
    "json": "bower.json"
}

Gruntfile.js:

bower: {
    install: {
        options: {
            install: true,
            copy: false,
            targetDir: './libs'
        }
    }
}

When I try to install Bower components using Grunt, I get the following errors:

Running "bower:install" (bower) task
...
bower validate 1.3.15 against git://github.com/angular/bower-angular.git#*
bower new version for git://github.com/angular/bower-angular.git#*
bower resolve git://github.com/angular/bower-angular.git#*
Fatal error: Arguments to path.join must be strings

Does anyone see what is wrong with my Gruntfile.js file and why I get this error when installing Bower components using Grunt? Thanks.


Solution

  • Here's how I have my configuration which is working for me:

    bower: {
                install: {
                    options: {
                        targetDir: bowerDir,
                        install: true,
                        cleanTargetDir: false,
                        cleanBowerDir: false,
                        bowerOptions: {}
                    }
                }
            }
    

    Also make sure you have the dependencies in your package.json file:

      "devDependencies": {
        "bower": "^1.3.1",
        "grunt": "^0.4.5",
        "grunt-bower-task": "^0.4.0",
        "grunt-cli": "^0.1.13",
    

    also try running these commands:

    npm install grunt-cli --save-dev
    npm install grunt-bower-task --save-dev