直接运行时karma失败,但npm确定

时间:2017-06-26 06:05:35

标签: node.js karma-mocha

如果我从npm运行业力,它可以正常工作。

npm run test

testpackage.json中定义:

"test": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run"

但是,如果我直接运行它,会发生错误

karma start test/unit/karma.conf.js --single-run

karma start test/unit/karma.conf.js --single-run
26 06 2017 13:53:13.399:ERROR [preprocess]: Can not load "webpack", it is not registered!
  Perhaps you are missing some plugin?
26 06 2017 13:53:13.402:ERROR [preprocess]: Can not load "sourcemap", it is not registered!
  Perhaps you are missing some plugin?
/Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/node_modules/.0.0.1@di/lib/injector.js:9
      throw error('No provider for "' + name + '"!');
      ^

Error: No provider for "framework:mocha"! (Resolving: framework:mocha)
    at error (/Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/node_modules/.0.0.1@di/lib/injector.js:22:12)
    at Object.get (/Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/node_modules/.0.0.1@di/lib/injector.js:9:13)
    at Injector.get (/Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/node_modules/.0.0.1@di/lib/injector.js:54:19)
    at /Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/lib/server.js:143:20
    at Array.forEach (native)
    at Server._start (/Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/lib/server.js:142:21)
    at Injector.invoke (/Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/node_modules/.0.0.1@di/lib/injector.js:75:15)
    at Server.start (/Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/lib/server.js:103:18)
    at Object.exports.run (/Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/lib/cli.js:280:26)
    at Object.<anonymous> (/Users/leon/.nvm/versions/node/v7.3.0/lib/node_modules/karma/bin/karma:3:23)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)

我很好奇,有什么区别?为什么抛出这个异常?我怎样才能直接运行业力?

1 个答案:

答案 0 :(得分:0)

也许尝试运行内部运行脚本cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run