javascript - Windows 10,运行 jest 时找不到现有的 binding.node 文件

标签 javascript node.js windows-10 electron jestjs

当在 appveyor 上和作为 virtualbox 运行 Windows 10 时,我在为我的 Electron 应用程序运行 Jest 测试时遇到了同样的错误。

 The specified module could not be found.
    \\?\C:\Users\User\peruse\app\node_modules\ref\build\Release\binding.node
      Error: The specified module could not be found.
      \\?\C:\Users\User\peruse\app\node_modules\ref\build\Release\binding.node
      at Runtime.requireModule (node_modules/jest-runtime/build/index.js:263:31)
      at bindings (app/node_modules/bindings/bindings.js:76:44)
      at Object.<anonymous> (app/node_modules/ref/lib/ref.js:5:47)

( https://ci.appveyor.com/project/joshuef/peruse/build/1.0.733/job/fwflo19to9rvt085#L4664 )

事情是......文件本身存在,通过运行确认:

dir  \\?\C:\Users\User\peruse\app\node_modules\ref\build\Release\binding.node 

结果是:

-a----         4/9/2018   1:44 AM         157696 binding.node

应用程序本身运行良好(它是一个 Electron 应用程序,通过 webpack 编译)。只有在针对 native 库运行测试时,我才会收到此错误。并且仅在 Windows 中。 (osx/linux 测试运行良好。)

我尝试过重建,使用 npm 而不是 yarn,通过命令行重新安装 vs2017 工具......系统(这是某事),但我不知道接下来要尝试什么...

Jest 正在从命令行运行。

Jest 是这样配置的:

module.exports = {
    verbose                : true,
    moduleFileExtensions   : ['js', 'jsx', 'json'],
    setupFiles   : ['raf/polyfill','<rootDir>/test/setup.js'],
    testPathIgnorePatterns : ['node_modules'],
    moduleDirectories      : ['app', 'test', 'node_modules', 'app/node_modules'],
    moduleNameMapper       : {
        "electron": "<rootDir>/mocks/electron.js",
        "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
        "<rootDir>/mocks/fileMock.js",
        "\\.(css|scss)$": "<rootDir>/mocks/fileMock.js",
        '^appPackage$'      : '<rootDir>/package.json',
        '^@actions(.*)$'    : '<rootDir>/app/actions$1',
        '^@components(.*)$' : '<rootDir>/app/components$1',
        '^@containers(.*)$' : '<rootDir>/app/containers$1',
        '^appConstants$'  : '<rootDir>/app/constants.js',
        '^@extensions(.*)$' : '<rootDir>/app/extensions$1',
        '^@logger$'     : '<rootDir>/app/logger.js',
        '^@reducers(.*)$'   : '<rootDir>/app/reducers$1',
        '^@store(.*)$'      : '<rootDir>/app/store',
        '^@utils(.*)$'      : '<rootDir>/app/utils$1'
    }
};

the appveyor config file is here .

任何需要检查的指示/想法/事情 super 表示赞赏。如果需要更多代码说明,请告诉我。

提前致谢!

最佳答案

我在 Windows 10 上的 ibm_db 模块中遇到了类似的错误(但在 Linux Docker 容器中没有):

The specified module could not be found.
\\?\C:\_projects\projectName\node_modules\ibm_db\build\Release\odbc_bindings.node

  at Runtime._loadModule (node_modules/jest-runtime/build/index.js:572:29)
  at bindings (node_modules/bindings/bindings.js:112:48)

找到解决方案 here :

  1. IBM site 下载 odbc 驱动程序.您可能需要注册 为此在 IBM 工作。
  2. 只需解压即可安装此 odbc 驱动程序 您下载到某个文件夹的包的内容,例如 例如“C:\IBMDB2\CLIDRIVER\”
  3. 将 IBM_DB_HOME 环境变量设置为指向包含驱动程序的文件夹。 ( 到 "C:\IBMDB2\CLIDRIVER\"如果您使用该路径)
  4. 在“PATH”环境变量中添加“%IBM_DB_HOME%\bin”路径。
  5. 重新启动或退出/登录以使对 PATH 的更改生效。
  6. 使用“npm install”重新安装包,因为所有这些环境变量仅在包安装阶段使用。

关于javascript - Windows 10,运行 jest 时找不到现有的 binding.node 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49729061/

相关文章:

javascript - 在javascript中调试符号的正确方法

javascript - 使用 Javascript 和 Hammer.js 查找同级

javascript - 在 Express 2.x 中的 dynamicHelper(或其他替代方案)中进行异步调用

node.js - MongoDB-Express::ENOTDIR:不是目录,...gssapi.js/package.json

sql - 使用 SSMS 2016 : Object cannot be cast from DBNull to other types 时出错

javascript - 单击按钮刷新页面

JavaScript 等待变量

javascript - 无法在 Node js的模块导出中正确返回

makefile - 如何将 PYTHONPATH 设置为 Windows 上的当前目录

user-interface - 在 Windows 上通过 OpenSSH 启动 GUI 程序?