无法为节点构建本机软件包

时间:2018-12-03 03:23:27

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

因此,我正在运行一个Electron应用程序,该应用程序具有一个称为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软件包。我可以使用另一个软件包,但我真的不必这样做,我想深入了解为什么我不愿构建这个软件包。

编辑:

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

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.

2 个答案:

答案 0 :(得分:2)

为我自己解决了这个问题:

  1. 删除节点模块文件夹

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

    npm install --global --production --vs2015 --add-python-to-path Windows-build-tools

    npm install --global --production --add-python-to-path Windows-build-tools node-gyp

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

    msvs_version = 2015

    python = python2.7

答案 1 :(得分:0)

首先从系统中删除所有已安装的Visual Studio版本,然后从pathsystem variable中删除条目。

,并遵循以下网址  https://github.com/nodejs/node-gyp#readme

better-sqlite3删除package.json这个程序包条目之后,一切都运行良好,因为其他程序包没有任何本机依赖性。并且此better-sqlite3是下载后的本机模块,此模块使用工具node-gpy进行构建,该工具将需要在系统上安装两件事,即pythonvisual studio

因此,请尝试按照上述URL步骤进行操作。

它肯定会工作。

相关问题