【问题标题】:When trying to use npm install I get a "msvsVersion is not defined" error on a discord bot尝试使用 npm install 时,我在不和谐机器人上收到“未定义 msvsVersion”错误
【发布时间】:2021-08-19 07:13:23
【问题描述】:

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

> sodium@3.0.2 preinstall C:\Users\fang2\Documents\Coding\Discord Bots\Myu-Bot-master\node_modules\sodium
> node install.js --preinstall

MS Version: 2017
C:\Users\fang2\Documents\Coding\Discord Bots\Myu-Bot-master\node_modules\sodium\install.js:312
    console.log('Invalid msvs_version ' + msvsVersion + '\n');
                                          ^

ReferenceError: msvsVersion is not defined
    at errorInvalidMSVSVersion (C:\Users\fang2\Documents\Coding\Discord Bots\Myu-Bot-master\node_modules\sodium\install.js:312:43)
    at checkMSVSVersion (C:\Users\fang2\Documents\Coding\Discord Bots\Myu-Bot-master\node_modules\sodium\install.js:329:9)
    at Object.<anonymous> (C:\Users\fang2\Documents\Coding\Discord Bots\Myu-Bot-master\node_modules\sodium\install.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:\Users\fang2\AppData\Roaming\npm-cache\_logs\2021-06-01T04_30_07_597Z-debug.log

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

【问题讨论】:

  • 我遇到了完全相同的问题,我们将不胜感激。

标签: node.js typescript discord.js sodium


【解决方案1】:

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

以下方法对我有用:

  1. 确保已安装 2015 Visual Studio Build Tools。
  2. 安装 Windows 8.1 SDK(似乎 node-addon-api 模块钠依赖于此)。 Microsoft 维护其 SDK here 的存档。 或者,您可以从 2017 Build Tools 安装程序的 Visual C++ 构建工具部分的可选下拉菜单中安装它。 Here is a screenshot of the menu for clarification.
  3. 在您的 Windows 环境变量中,添加 VCTargetsPath 并将其设置为 C:\Program Files (x86)\MSBuild\Microsoft.cpp\v4.0\v140Source
  4. 运行npm config set msvs_version 2015
  5. 现在运行 npm install sodiumnpm install(如果已列为项目的依赖项)时会生成钠。

值得一提的东西:

第 3 步可防止错误 MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. 抛出并导致构建失败。从我的项目文件夹中,它追踪到node_modules\sodium\node-addon-api\nothing.vcxproj(20,3)

很多在线资源建议安装 windows-build-toolsnpm install --global --production windows-build-tools --vs2015 以使此构建成功,但截至 2020 年 2 月,the Node.js installer now includes build tools for Windows as an option。仅当您尚未安装 2015 构建工具时,这才是相关的。

希望我能提供帮助。

【讨论】:

    猜你喜欢
    • 2017-04-26
    • 2020-09-17
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    相关资源
    最近更新 更多