node.js - 无法为 Node 构建 native 包

标签 node.js npm electron node-gyp electron-rebuild

所以我正在运行一个 Electron 应用程序,它有一些 native 模块,其中一个是名为 better-sqlite3 的包。 。我运行yarn,yarn能够毫无问题地安装所有包,但是当它到达构建步骤时,一切都会崩溃。

我得到了一堆不同的node-gyp我已经能够保存其中 2 个错误输出,因此我可以在这里显示第一个错误的错误输出的重要部分:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Platform.targets(67,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\bepop\Documents\DeveloperData\Clippy\app\node_modules\better-sqlite3\build\deps\action_before_build.vcxproj]

Full error

就这个错误而言,我尝试了多种方法,例如以多种不同的方式安装 microsoft Visual 构建工具,例如手动访问他们的网站并下载 IDE,我还尝试通过 NPM 安装构建工具:

npm install --global --production windows-build-tools

它总是成功安装构建工具,但仍然出错,我还尝试使用以下命令编辑 npm 配置:npm config set msvs_version 2017 还是不行。我还尝试去安装 Visual Studio 并手动检查:“VC+​​+ 2017 版本 15.7 v14.14 最新 v141 工具” 也没什么。

我确实记得在某个时候我能够使用 Windows 10 正常构建所有内容,并且从来没有遇到过问题,但现在不会了。几个月来我一直在尝试自己解决这个问题,而且我一直坚持在我的 MacBook 上处理这个项目,在构建 better-sqlite3 时从来没有出现过问题。包。

我尝试过的另一件事是彻底清除计算机上的所有内容并重新开始,因为在某些时候我改变了很多东西,以至于我忘记了我安装了什么和没有安装什么。

如果我删除 better-sqlite3包来自package.json文件一切运行顺利,我能够正常运行我的项目,但我需要 better-sqlite3包裹。我可以使用另一个包,但我真的不应该这样做,我想弄清楚为什么我不构建这个包。

编辑:

更新:我将 Microsoft 构建工具 v14.0.23107.0 添加到我的 pats 变量中,现在它输出错误:

C:\Users\bepop\Documents\DeveloperData\Clippy\node_modules\integer\build\integer.vcxproj(21,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

最佳答案

我自己解决了这个问题:

  1. 删除 Node 模块文件夹

  • 使用管理员权限打开PowerShell并按顺序运行

    npm install --global --product --vs2015 --add-python-to-path windows-build-tools

    npm install --global --product --add-python-to-path windows-build-tools node-gyp

  • 转到 ~/.npmrc 并确保这些是您的设置:

    msvs_version=2015

    python=python2.7

  • 关于node.js - 无法为 Node 构建 native 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53587048/

    相关文章:

    node.js - 如何从 typescript 使用 npm 模块?

    node.js - 在 Electron 应用程序的 Squirrel 事件中执行 createShortcut

    javascript - 像 Trello 这样的项目,在 Mongoose 中创建一个合适的数据库

    angularjs - 发送 $http.get 两次

    javascript - 在 Windows 10 中使用 NodeJS 在本地运行异步函数

    node.js - NPM 无法在 Windows 上运行 - 路径中有两个 C 驱动器

    npm - 单个 session 中的 Ansible npm 安装列表

    javascript - Node.js 递归列出文件的完整路径

    javascript - 如何将 Nedb 与 Electron 集成

    node.js - Express.js 和 Neo4j