首页 > 编程语言 >Nodejs安装karma 出现 Cannot find module 'optimist'错误

Nodejs安装karma 出现 Cannot find module 'optimist'错误

时间:2022-09-02 09:15:54浏览次数:65  
标签:npm Nodejs 0.0 module js Cannot karma packages

http://www.javashuo.com/article/p-pnrbedet-dc.html

原文   https://segmentfault.com/a/119000001188388

安装好nodejs、配置好cnpm、以及自动化测试所需的karma-cli、karma和jasmine以后node

$ npm install -g karma-cli

$ cnpm install karma --save-dev
√ Installed 1 packages
√ Linked 0 latest versions
√ Run 0 scripts
√ All packages installed (used 172ms, speed 110.67kB/s, json 1(19.04kB), tarball 0B)

$ npm install karma-jasmine karma-chrome-launcher --save-dev
npm WARN [email protected] requires a peer of karma@>=0.9 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

+ [email protected]
+ [email protected]
removed 422 packages and updated 2 packages in 5.129s

运行出错chrome

$ karma start
module.js:538
    throw err;
    ^

Error: Cannot find module 'optimist'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\von\path\to\work\node_modules\[email protected]@karma\lib\cli.js:2:16)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)

解决:npm

$ cat package.json
{
  "name": "myname",
  "version": "0.0.1",
  "devDependencies": {
    "karma": "^1.7.1",
    "karma-chrome-launcher": "^0.1.12",
    "karma-jasmine": "^0.2.3"
  }
}

$ rm node_modules/ -rf
$ npm cache clean --force
$ cnpm install
platform unsupported [email protected][email protected] › fsevents@^1.0.0 Package require os(darwin) not compatible with your platform(win32)
[fsevents@^1.0.0] optional install error: Package require os(darwin) not compatible with your platform(win32)
√ Installed 3 packages
√ Linked 156 latest versions
√ Run 0 scripts
anti semver [email protected][email protected][email protected] delcares [email protected](resolved as 0.0.33) but using ancestor(karma)'s dependency [email protected](resolved as 0.0.31)
√ All packages installed (175 packages installed from npm registry, used 5s, speed 58.01kB/s, json 159(311.04kB), tarball 0B)

标签:npm,Nodejs,0.0,module,js,Cannot,karma,packages
From: https://www.cnblogs.com/slqgenius/p/16648572.html

相关文章