grunt-karma ^2.0.0 不使用 karma@0.13.x 并且它中断了

grunt-karma ^2.0.0 does NOT use karma@0.13.x and it breaks

安装 grunt-karma 时 npm install grunt-karma --save-dev 会安装 karma^1.0.0。这打破了测试:

Warning: .then() only accepts functions but was passed: [object Undefined], [object Undefined]...

确实,在安装 grunt-karma 时,我收到以下 npm WARN 消息:

npm WARN peerDependencies The peer dependency grunt@>=0.4.x included from grunt-karma will no npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly. npm WARN peerDependencies The peer dependency karma@^0.13.0 || >= 0.14.0-rc.0 included from grunt-karma will no npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly. npm WARN optional dep failed, continuing fsevents@1.0.12

但是我的 npm 版本是 2.14.20

这是安装的内容:

grunt@1.0.1 node_modules\grunt
├── grunt-known-options@1.1.0
├── path-is-absolute@1.0.0
├── eventemitter2@0.4.14
├── rimraf@2.2.8
├── exit@0.1.2
├── nopt@3.0.6 (abbrev@1.0.9)
├── iconv-lite@0.4.13
├── coffee-script@1.10.0
├── glob@7.0.5 (fs.realpath@1.0.0, inherits@2.0.1, inflight@1.0.5, once@1.3.3)
├── minimatch@3.0.2 (brace-expansion@1.1.5)
├── findup-sync@0.3.0 (glob@5.0.15)
├── grunt-cli@1.2.0 (resolve@1.1.7)
├── js-yaml@3.5.5 (esprima@2.7.2, argparse@1.0.7)
├── dateformat@1.0.12 (get-stdin@4.0.1, meow@3.7.0)
├── grunt-legacy-log@1.0.0 (hooker@0.2.3, colors@1.1.2, underscore.string@3.2.3, lodash@3.10.1, grunt-legacy-log-utils@1.0.0)
└── grunt-legacy-util@1.0.0 (getobject@0.1.0, async@1.5.2, hooker@0.2.3, which@1.2.10, underscore.string@3.2.3, lodash@4.3.0)

karma@1.0.0 node_modules\karma   <-- here is the issue 
├── graceful-fs@4.1.4
├── di@0.0.1
├── rimraf@2.5.2
├── mime@1.3.4
├── qjobs@1.1.4
├── colors@1.1.2
├── source-map@0.5.6
├── http-proxy@1.14.0 (eventemitter3@1.2.0, requires-port@1.0.0)
├── isbinaryfile@3.0.0
├── dom-serialize@2.2.1 (custom-event@1.0.0, void-elements@2.0.1, extend@3.0.0, ent@2.2.0)
├── glob@7.0.5 (path-is-absolute@1.0.0, fs.realpath@1.0.0, inherits@2.0.1, inflight@1.0.5, once@1.3.3)
├── minimatch@3.0.2 (brace-expansion@1.1.5)
├── useragent@2.1.9 (lru-cache@2.2.4)
├── tmp@0.0.28 (os-tmpdir@1.0.1)
├── bluebird@3.4.1
├── connect@3.4.1 (utils-merge@1.0.0, parseurl@1.3.1, debug@2.2.0, finalhandler@0.4.1)
├── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)
├── body-parser@1.15.2 (content-type@1.0.2, bytes@2.4.0, depd@1.1.0, qs@6.2.0, raw-body@2.1.7, on-finished@2.3.0, http-errors@1.5.0, debug@2.2.0, iconv-lite@0.4.13, type-is@1.6.13)
├── expand-braces@0.1.2 (array-unique@0.2.1, array-slice@0.2.3, braces@0.1.5)
├── chokidar@1.6.0 (path-is-absolute@1.0.0, inherits@2.0.1, glob-parent@2.0.0, async-each@1.0.0, is-binary-path@1.0.1, is-glob@2.0.1, readdirp@2.0.1, anymatch@1.3.0)
├── socket.io@1.4.8 (has-binary@0.1.7, debug@2.2.0, socket.io-parser@2.2.6, socket.io-adapter@0.4.0, engine.io@1.6.11, socket.io-client@1.4.8)
├── log4js@0.6.37 (semver@4.3.6, readable-stream@1.0.34)
├── lodash@3.10.1
├── combine-lists@1.0.0 (lodash@4.13.1)
└── core-js@2.4.0

grunt-karma@2.0.0 node_modules\grunt-karma
└── lodash@3.10.1

解决方案是根据文档安装 grunt-karma 需要的版本:

This current version uses karma`@0.13.x ...

Although it the tables it seems to depend of different versions of karma for devDependencies(1.x || ^0.13.0) and peerDependencies(^0.13.0 || >= 0.14.0-rc.0)

因此,要修复它,您必须手动安装正确版本的 karma,直到问题得到解决:

npm install karma@0.13.22