Gatsby project creation error . Error: Could not find any Visual Studio installation to use

Gatsby project creation error . Error: Could not find any Visual Studio installation to use

我的系统上安装了 visual studio code 2017 我在通过 cli 命令创建的 gatsby 新项目中遇到了这些错误

gatsby new

错误如下

gatsby new
create-gatsby version 2.2.0



                                                   Welcome to Gatsby!



This command will generate a new Gatsby site for you in E:\GATSBY with the setup you select. Let's answer some
questions:



What would you like to call your site?
√ · My Gatsby Site
What would you like to name the folder where your site will be created?
√ GATSBY/ my-gatsby-site
√ Will you be using a CMS?
· No (or I'll add it later)
√ Would you like to install a styling system?
· No (or I'll add it later)


Thanks! Here's what we'll now do:

    Create a new Gatsby site in the folder my-gatsby-site


√ Created site from template
> Installing Gatsby...

gyp ERR! find VS
gyp ERR! find VS msvs_version was set from command line or npm config
gyp ERR! find VS - looking for Visual Studio version 2015
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS checking VS2017 (15.9.28307.1745) found at:
gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio17\Community"
gyp ERR! find VS - found "Visual Studio C++ core features"
gyp ERR! find VS - found VC++ toolset: v141
gyp ERR! find VS - found Windows SDK: 10.0.17763.0
gyp ERR! find VS - msvs_version does not match this version
gyp ERR! find VS checking VS2017 (15.9.28307.1525) found at:
gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools"
gyp ERR! find VS - found "Visual Studio C++ core features"
gyp ERR! find VS - found VC++ toolset: v141
gyp ERR! find VS - found Windows SDK: 10.0.17763.0
gyp ERR! find VS - msvs_version does not match this version
gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS valid versions for msvs_version:
gyp ERR! find VS - "2017"
gyp ERR! find VS - "C:\Program Files (x86)\Microsoft Visual Studio17\Community"
gyp ERR! find VS - "2017"
gyp ERR! find VS - "C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools"
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:326:5)
gyp ERR! stack     at ChildProcess.emit (events.js:376:20)
gyp ERR! stack     at maybeClose (internal/child_process.js:1055:16)
gyp ERR! System Windows_NT 10.0.19043
gyp ERR! command "C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd E:\GATSBY\my-gatsby-site\node_modules\msgpackr-extract
gyp ERR! node -v v14.17.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
gyp ERR! find VS
gyp ERR! find VS msvs_version was set from command line or npm config
gyp ERR! find VS - looking for Visual Studio version 2015
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS checking VS2017 (15.9.28307.1745) found at:
gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio17\Community"
gyp ERR! find VS - found "Visual Studio C++ core features"
gyp ERR! find VS - found VC++ toolset: v141
gyp ERR! find VS - found Windows SDK: 10.0.17763.0
gyp ERR! find VS - msvs_version does not match this version
gyp ERR! find VS checking VS2017 (15.9.28307.1525) found at:
gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools"
gyp ERR! find VS - found "Visual Studio C++ core features"
gyp ERR! find VS - found VC++ toolset: v141
gyp ERR! find VS - found Windows SDK: 10.0.17763.0
gyp ERR! find VS - msvs_version does not match this version
gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS valid versions for msvs_version:
gyp ERR! find VS - "2017"
gyp ERR! find VS - "C:\Program Files (x86)\Microsoft Visual Studio17\Community"
gyp ERR! find VS - "2017"
gyp ERR! find VS - "C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools"
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:326:5)
gyp ERR! stack     at ChildProcess.emit (events.js:376:20)
gyp ERR! stack     at maybeClose (internal/child_process.js:1055:16)
gyp ERR! System Windows_NT 10.0.19043
gyp ERR! command "C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd E:\GATSBY\my-gatsby-site\node_modules\lmdb-store
gyp ERR! node -v v14.17.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lmdb-store@1.6.13 install: `node-gyp-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the lmdb-store@1.6.13 install 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:

 ERROR

Command failed with exit code 1: npm install --loglevel error --color always

> msgpackr-extract@1.0.15 install E:\GATSBY\my-gatsby-site\node_modules\msgpackr-extract
> node-gyp-build


E:\GATSBY\my-gatsby-site\node_modules\msgpackr-extract>if not defined npm_config_node_gyp (node "C:\Program Files
(x86)\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\..\..\node_modules\node-gyp\bin\node-gyp.js"
rebuild )  else (node "C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )

> lmdb-store@1.6.13 install E:\GATSBY\my-gatsby-site\node_modules\lmdb-store
> node-gyp-build


E:\GATSBY\my-gatsby-site\node_modules\lmdb-store>if not defined npm_config_node_gyp (node "C:\Program Files
(x86)\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\..\..\node_modules\node-gyp\bin\node-gyp.js"
rebuild )  else (node "C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )

编辑:

错误

 npm install --global windows-build-tools --vs2015                                               npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported

> windows-build-tools@5.2.2 postinstall C:\Users\farih\AppData\Roaming\npm\node_modules\windows-build-tools
> node ./dist/index.js



Downloading python-2.7.15.msi
[>                                            ] 0.0% (0 B/s)
Downloaded python-2.7.15.msi. Saved to C:\Users\farih\.windows-build-tools\python-2.7.15.msi.
Downloading BuildTools_Full.exe
[>                                            ] 0.0% (0 B/s)
Downloaded BuildTools_Full.exe. Saved to C:\Users\farih\.windows-build-tools\BuildTools_Full.exe.

Starting installation...
Launched installers, now waiting for them to finish.
This will likely take some time - please be patient!

Status from the installers:
---------- Visual Studio Build Tools ----------
[3C84:46EC][2021-11-26T00:41:36]i000: Setting string variable 'LastGoodSource' to value 'Web'
[3C84:46EC][2021-11-26T00:41:36]i000: Setting string variable 'IsWebBundle' to value 'True'
[3C84:46EC][2021-11-26T00:41:36]i000: MUX:  Ux Uninitialized
[3C84:46EC][2021-11-26T00:41:36]i000: MUX:  Exit with 0x643 (Failed)
[3C84:1114][2021-11-26T00:41:36]i500: Shutting down, exit code: 0x643
------------------- Python --------------------
Successfully installed Python 2.7


Could not install Visual Studio Build Tools.
Please find more details in the log files, which can be found at
C:\Users\farih\.windows-build-tools

Now configuring Python...

All done!

+ windows-build-tools@5.2.2
added 148 packages from 102 contributors in 380.326s

我的问题是 msvs 版本未设置,如错误中所述 msvs_version 与此版本不匹配 我运行

npm install --global windows-build-tools --vs2017
npm config set msvs_version 2017.

参考文档here