运行Grunt时,path.resolve的参数必须是string

我的Grunt文件:

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"]); }; 

(我正在使用grunt-ts 。)

系统信息

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

我已经search了互联网,发现有关这个错误的许多资源,但他们都说,应该升级NodeJS和/或Grunt。 我已经试过了。 我甚至完全重新安装了Grunt,但是,错误依然存在。


完整的错误信息:

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

在比较我的Gruntfile和正式提供的示例文件之后 ,我发现我真的很愚蠢的错误:

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

out 不能是一个数组!
正确的版本:

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

所以在我的情况下, package.json中的节点模块的main属性是一个数组,而不是一个string,在history.js的package.json中是一个例子:

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

我发现这一点的方式是去错误发生在我的node_modules,然后做了正确的上方console.log(pkg.main)

原始堆栈跟踪:

 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)