Grunt Rants

Crazy how hard it is to start projects from scratch, and pick the best modern technologies. Seems like always someone’s already made a bad choice I then have to deal with.

Grunt: automation

  1. “So little time, so much to do!”, and stack gets ever more complex. So, don’t repeat yourself (DRY) — automate everything: minification, combining, running, reloading, testing, deploying…
  2. Goals, specifically: run (local development), and deploy to Appfog.

NPM mess

Installing Grunt was painful! It had to do with migrating from 0.3 to 0.4.

  1. $ grunt
    <FATAL> Unable to find "grunt.js" config file. Do you need any --help? </FATAL>

    Took some time to find I had an old Grunt (v0.3.17) installed globally, and in /usr/lib/node_modules/grunt/ instead of under /usr/local/lib/node_modules/ , so NPM refused to uninstall it:

    $ sudo npm uninstall -g grunt
    npm WARN uninstall not installed in /usr/local/lib/node_modules: "grunt"

    WTF? Nu, deleted it manually, including symlink in $PATH:

    $ sudo rm -r /usr/lib/node_modules/grunt/
    $ sudo rm /usr/bin/grunt

    Still, --version picks up an old one?!

    $ grunt --version
    grunt-cli v0.1.11
    grunt v0.3.17
    $ whereis grunt
    grunt: /usr/local/bin/grunt
    $ ll /usr/local/bin/grunt
    lrwxrwxrwx 1 root root 39 Jan 7 11:50 /usr/local/bin/grunt -> ../lib/node_modules/grunt-cli/bin/grunt*

    Getting rid of grunt-cli, too:

    $ sudo npm uninstall -g grunt-cli
    unbuild grunt-cli@0.1.11

    Anyway, like BA says, prefer installing Grunt locally.

    $ npm install --save-dev grunt

    (dev or dep? If it’s global, does it go into package.json at all?)
    But, if local, won’t be symlinked somewhere in $PATH, and running it with

    $ ~/node_modules/grunt/bin/grunt

    is painful! Symlink it myself? Anyway, it bombs!

    $ ~/node_modules/grunt/bin/gruntpath.js:313
    throw new TypeError('Arguments to path.resolve must be strings');

    NPM installed it globally, but didn’t create a symlink?! WTF?

    $ grunt --version
    grunt: command not found

    *Not* a permissions problem — grunt.js isn’t executable! That’s what grunt-cli is for. This explains the wrapper function, too.
    Installed it globally, but gives an old version, again!? What a nightmare! And again…

    $ sudo npm uninstall -g grunt-cli
    unbuild grunt-cli@0.1.11
    $ grunt --version
    bash: /usr/local/bin/grunt: No such file or directory
  2. Again, starting from scratch, this is how it works: grunt locally, grunt-cli globally:
    $ npm install --save-dev grunt
    grunt@0.4.2 node_modules/grunt
    $ npm install --global grunt-cli
    /usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
    grunt-cli@0.1.11 /usr/local/lib/node_modules/grunt-cli
    $ grunt --version
    grunt-cli v0.1.11
    grunt v0.4.2

    package.json now has:

    "devDependencies": {
    	"grunt": "~0.4.2"


  3. Reportedly, this grunt/grunt-cli separation will allow installing multiple versions of Grunt (locally), and still using the command line globally. Nu, except if they break it again.


So much nicer!

Just run the app

  1. $ npm start
    > foo@0.0.1 start ~/foo
    > node server.js
    Config initialized in development mode
    Initialize passport
    Express app started on port 3000
  2. Ah, but thru nodemon to survive exceptions, and watch for changed files to keep developers (me!) happy. Or do I want to not run nodemon when in development mode? Which Grunt plugin? grunt-nodemon

Comments are closed.