【问题标题】:Arguments to path.resolve must be strings when running Grunt运行 Grunt 时 path.resolve 的参数必须是字符串
【发布时间】:2014-01-23 02:53:17
【问题描述】:

我的 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
  • 咕噜 v0.4.2

我已经在网上搜索了很多关于这个错误的资源,但是他们都说应该升级 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"
  }
}

【问题讨论】:

    标签: node.js gruntjs npm


    【解决方案1】:

    所以在我的特殊情况下,package.json 中节点模块的 main 属性是一个数组而不是字符串,例如 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)
    

    【讨论】:

      【解决方案2】:

      在将我的 Gruntfile 与官方提供的 sample file 进行比较后,我发现我的 非常愚蠢 错误:

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

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

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

      【讨论】:

      • 很棒的发现!我刚刚遇到了同样的问题,你的帖子真的很有帮助。
      • 有同样的错误。真的很神秘的错误信息。感谢您的帮助。
      猜你喜欢
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 2015-03-24
      • 2020-05-05
      • 2017-05-06
      相关资源
      最近更新 更多