node.js - WSL : mocha from sudo apt install mocha crashes with fresh install

标签 node.js linux ubuntu mocha.js

正如你在下面看到的,我从 which mocha 的状态开始。什么都不返回(未安装),然后用 sudo apt install mocha 安装它,然后简单地运行 mocha希望收到某种“使用/帮助选项以获取更多信息”。
但是,相反,我收到了这个

Error: Cannot find module 'glob'


为什么是这样?
REDACTED:/mnt/d/SourceTree$ which mocha

REDACTED:/mnt/d/SourceTree$ sudo apt install mocha
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gyp libauthen-sasl-perl libdata-dump-perl libencode-locale-perl libfile-basedir-perl libfile-desktopentry-perl libfile-listing-perl   
  libfile-mimeinfo-perl libfont-afm-perl libhtml-form-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl
  libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-date-perl libhttp-message-perl libhttp-negotiate-perl
  libio-html-perl libio-socket-ssl-perl libio-stringy-perl libipc-system-simple-perl libjs-is-typedarray libjs-psl
  libjs-typedarray-to-buffer liblwp-mediatypes-perl liblwp-protocol-https-perl libmailtools-perl libnet-dbus-perl libnet-http-perl      
  libnet-smtp-ssl-perl libnet-ssleay-perl libnode-dev libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib libtie-ixhash-perl     
  libtimedate-perl libtry-tiny-perl liburi-perl libuv1-dev libwww-perl libwww-robotrules-perl libx11-protocol-perl libxml-parser-perl   
  libxml-twig-perl libxml-xpathengine-perl perl-openssl-defaults python-pkg-resources python2 python2-minimal python2.7
  python2.7-minimal python3-cliapp python3-markdown python3-packaging python3-pyparsing python3-ttystatus xdg-utils
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  chai
The following NEW packages will be installed:
  mocha
0 upgraded, 1 newly installed, 0 to remove and 123 not upgraded.
Need to get 0 B/113 kB of archives.
After this operation, 675 kB of additional disk space will be used.
Selecting previously unselected package mocha.
(Reading database ... 72405 files and directories currently installed.)
Preparing to unpack .../mocha_7.0.1+ds1-2_all.deb ...
Unpacking mocha (7.0.1+ds1-2) ...
Setting up mocha (7.0.1+ds1-2) ...
Processing triggers for man-db (2.9.1-1) ...

REDACTED:/mnt/d/SourceTree$ mocha
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'glob'
Require stack:
- /usr/share/nodejs/mocha/lib/utils.js
- /usr/share/nodejs/mocha/bin/mocha
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/usr/share/nodejs/mocha/lib/utils.js:15:12)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/share/nodejs/mocha/lib/utils.js',
    '/usr/share/nodejs/mocha/bin/mocha'
  ]
}

最佳答案

尝试这个 :
npm install --save module_name (在你的情况下是 glob)
(npm install --save glob)
更多信息 已经有一个 issue报告此错误消息:

关于node.js - WSL : mocha from sudo apt install mocha crashes with fresh install,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71461463/

相关文章:

node.js - 尽管 Promise 已解析,为什么 .then() 在这个 Node JS 示例中从未执行?

linux - 未指定操作大小

javascript - ExpressJS Route 中的正则表达式

html - 在controller.js文件中处理AngularJS中的错误

ruby-on-rails - 无法在 RVM、OS Linux Mint 17 上安装 Rails

c - 如何编译 APR 测试脚本

mysql - 在 Ubuntu 14.04 上与 MySQL 一起安装后无法启动 MariaDB

bash - 如何逐行使用 sed?

java - ObfuscatedFontPart.deleteEmbeddedFontTempFiles 中的 docx4j NullPointerException

Javascript:检查对象数组中是否存在键