尝试使用 npm install 时,我得到一个“未定义 msvsVersion".不和谐机器人上的错误 [英] When trying to use npm install I get a "msvsVersion is not defined" error on a discord bot

查看:13
本文介绍了尝试使用 npm install 时,我得到一个“未定义 msvsVersion".不和谐机器人上的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试自行托管 TypeScript discord 机器人,但设置过程一直令人困惑.我认为它应该使用 index.js 文件创建一个 build 目录,但我不确定.我已经安装了 Visual Studio Build Tools 2017,因为它似乎需要它们,但运行 npm install 会出现此错误:

I've been trying to self-host a TypeScript discord bot, but the setup process has been nothing but confusing. I think it's supposed to create a build directory with an index.js file, but I'm not sure. I've installed Visual Studio Build Tools 2017 because it seems to need them, but running npm install gives this error:

> sodium@3.0.2 preinstall C:Usersfang2DocumentsCodingDiscord BotsMyu-Bot-master
ode_modulessodium
> node install.js --preinstall

MS Version: 2017
C:Usersfang2DocumentsCodingDiscord BotsMyu-Bot-master
ode_modulessodiuminstall.js:312
    console.log('Invalid msvs_version ' + msvsVersion + '
');
                                          ^

ReferenceError: msvsVersion is not defined
    at errorInvalidMSVSVersion (C:Usersfang2DocumentsCodingDiscord BotsMyu-Bot-master
ode_modulessodiuminstall.js:312:43)
    at checkMSVSVersion (C:Usersfang2DocumentsCodingDiscord BotsMyu-Bot-master
ode_modulessodiuminstall.js:329:9)
    at Object.<anonymous> (C:Usersfang2DocumentsCodingDiscord BotsMyu-Bot-master
ode_modulessodiuminstall.js:353:5)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sodium@3.0.2 preinstall: `node install.js --preinstall`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sodium@3.0.2 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:Usersfang2AppDataRoaming
pm-cache\_logs2021-06-01T04_30_07_597Z-debug.log

我尝试了 2019 构建工具和 2017 构建工具,并尝试手动设置 msvs 版本,但似乎没有任何效果.任何帮助将不胜感激.

I've tried both the 2019 build tools and the 2017 build tools, and tried setting the msvs version manually, but nothing seems to have worked. Any help would be greatly appreciated.

推荐答案

我也在尝试让钠为 Discord 机器人工作,并花费了大量时间未能构建它.在撰写本文时,钠仅支持 msvs_version 配置为 2010201220132015.

I am also attempting to get sodium working for the purposes of a Discord bot and spent a considerable amount of time failing to build it. At the time of writing sodium only supports msvs_version configured to 2010, 2012, 2013 and 2015.

以下方法对我有用:

  1. 确保已安装 2015 Visual Studio Build Tools.
  2. 安装 Windows 8.1 SDK(似乎 node-addon-api 模块钠依赖于此).Microsoft 在此处维护其 SDK 的存档.或者,您可以从 2017 Build Tools 安装程序的 Visual C++ 构建工具部分的可选下拉菜单中安装它.这里是菜单的截图以供澄清.
  3. 在您的 Windows 环境变量中,添加 VCTargetsPath 并将其设置为 C:Program Files (x86)MSBuildMicrosoft.cppv4.0v140.来源
  4. 运行 npm config set msvs_version 2015
  5. 现在,当运行 npm install sodiumnpm install(如果已列为您项目的依赖项)时,将生成钠.
  1. Make sure 2015 Visual Studio Build Tools is installed.
  2. Install the Windows 8.1 SDK (it appears the node-addon-api module sodium is dependent on requires this). Microsoft maintains an archive of their SDKs here. Alternatively, you can install it from the optional drop-down menu in the Visual C++ build tools section from the 2017 Build Tools installer. Here is a screenshot of the menu for clarification.
  3. In your Windows environment variables, add VCTargetsPath and set it to C:Program Files (x86)MSBuildMicrosoft.cppv4.0v140. Source
  4. Run npm config set msvs_version 2015
  5. Now sodium will build when running npm install sodium or npm install if already listed as a dependency of your project.

值得一提的东西:

步骤 3 防止错误 MSB4019: 导入的项目C:Microsoft.Cpp.Default.props"找不到. 从抛出和失败构建.从我的项目文件夹中,它跟踪到 node_modulessodium ode-addon-api othing.vcxproj(20,3)

Step 3 prevents the error MSB4019: The imported project "C:Microsoft.Cpp.Default.props" was not found. from throwing and failing the build. From my project folder it traces to node_modulessodium ode-addon-api othing.vcxproj(20,3)

很多在线资源推荐安装 windows-build-toolsnpm install --global --production windows-build-tools --vs2015 以使此构建成功,但截至 2020 年 2 月,Node.js 安装程序现在包括为 Windows 构建工具作为一个选项.仅当您尚未安装 2015 构建工具时,这才是相关的.

A lot of resources online recommend installing windows-build-tools with npm install --global --production windows-build-tools --vs2015 to get this build to succeed but as of February 2020, the Node.js installer now includes build tools for Windows as an option. This should only be relevant if you don't already have 2015 build tools installed.

希望我能提供帮助.

这篇关于尝试使用 npm install 时,我得到一个“未定义 msvsVersion".不和谐机器人上的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆