Arguments to path.resolve must be strings when running Grunt

Problem

My Grunt file:

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        ts: {
            dev: {
                src: ["src/background/*.ts"],
                out: ["build/background.js"],
            }
        }
    });

    grunt.loadNpmTasks("grunt-ts");
    grunt.registerTask("default", ["ts:dev"]);
};

(I am using grunt-ts.)

System info

  • Windows 8.1
  • NodeJS v0.10.24
  • grunt-cli v0.1.11
  • grunt v0.4.2

I've already searched the Internet and found many resources about this error, but they all say that one should upgrade NodeJS and/or Grunt. I've already tried that. I had even completely re-installed Grunt, however, the error remained.


The complete error message:

P:\my-folder>grunt ts
Running "ts:dev" (ts) task
Warning: Arguments to path.resolve must be strings Use --force to continue

Aborted due to warnings.

package.json

{
  "name": "regex-search",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.2",
    "grunt-contrib-jshint": "~0.6.3",
    "grunt-contrib-nodeunit": "~0.2.0",
    "grunt-contrib-uglify": "~0.2.2",
    "grunt-ts": "~1.5.1"
  }
}
Problem courtesy of: ComFreek

Solution

After comparing my Gruntfile with the officially provided sample file, I found my really silly mistake:

ts: {
  dev: {
    src: ["src/background/*.ts"],
    out: ["build/background.js"],
  }
}

out must not be an array!
The correct version:

ts: {
  dev: {
    src: ["src/background/*.ts"],
    out: "build/background.js",
  }
}
Solution courtesy of: ComFreek

Discussion

So in my particular case, a node module's main attribute in package.json was an array and not a string, example in history.js' package.json:

{
     "main": [ './history.js', './history.adapter.ender.js' ]
}

The way I found this out was going to where the error originated in my node_modules and then did console.log(pkg.main) right above it.

Original stacktrace:

Fatal error: Arguments to path.resolve must be strings
TypeError: Arguments to path.resolve must be strings
    at Object.posix.resolve (path.js:422:13)
    at /Users/ebower/work/renvy/node_modules/browserify/node_modules/resolve/lib/async.js:153:38
    at fs.js:336:14
    at /Users/ebower/work/renvy/node_modules/grunt-browserify/node_modules/watchify/node_modules/chokidar/node_modules/readdirp/node_modules/graceful-fs/graceful-fs.js:104:5
    at /Users/ebower/work/renvy/node_modules/grunt-mocha/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/graceful-fs.js:104:5
    at FSReqWrap.oncomplete (fs.js:99:15)
Discussion courtesy of: neurosnap

This recipe can be found in it's original form on Stack Over Flow.