LevelDOWN:NODE_MODULE_VERSION 测试时出错,但不是 运行

LevelDOWN: NODE_MODULE_VERSION error when testing, but not running

我有一个 .npmrc 文件:

runtime = electron
target = 1.7.9
target_arch = x64
disturl = https://atom.io/download/atom-shell
build_from_source = true

还有一个package.json文件:

"scripts": {
    "start": "electron .",
    "test": "mocha"
}

npm install 之后,当我 运行 我的 node.js 脚本使用 npm start 时,一切都按预期进行。但是,当我使用 npm test 时,我 运行 遇到错误:

Uncaught LevelUPError: Failed to require LevelDOWN (The module '/Users/_me_/_project_/node_modules/leveldown/build/Release/leveldown.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 54. This version of Node.js requires NODE_MODULE_VERSION 57. Please try re-compiling or re-installing the module (for instance, using 'npm rebuild' or 'npm install').). Try 'npm install leveldown' if it's missing

我的 test.js 文件使用了一小部分不需要电子的模块。

我在清除 npm_modules 目录后尝试了 运行ning npm rebuildnpm installnpm install leveldown,但错误仍然存​​在。

知道为什么我会看到这些错误或如何更正此问题吗?

编辑:我能够用 electron-mocha 切换 mocha 并绕过错误。

  1. npm 缓存清理
  2. npm 安装
  3. electron-rebuild(需要 npm install electron-rebuild)

我用这些方法解决了问题