1. 程式人生 > 其它 >windows安裝nodejieba踩坑記錄

windows安裝nodejieba踩坑記錄

npm install 的時候總是會出現下面的錯誤:

gyp info find Python using Python version 3.8.6 found at "C:\Program Files\python\python.exe"
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 2017
gyp ERR! find VS VCINSTALLDIR not set
, not running in VS Command Prompt gyp ERR! find VS checking VS2019 (16.11.31624.102) found at: gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools" gyp ERR! find VS - found "Visual Studio C++ core features" gyp ERR! find VS - found VC++ toolset: v142 gyp ERR! find VS - found Windows SDK: 10.0
.19041.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 - "2019" gyp ERR! find VS - "C:\Program Files (x86)\Microsoft Visual Studio\2019\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:\Users\Administrator\AppData\Roaming\nvm\v16.8.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47) gyp ERR! stack at C:\Users\Administrator\AppData\Roaming\nvm\v16.8.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16 gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Users\Administrator\AppData\Roaming\nvm\v16.8.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14) gyp ERR! stack at C:\Users\Administrator\AppData\Roaming\nvm\v16.8.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14 gyp ERR! stack at C:\Users\Administrator\AppData\Roaming\nvm\v16.8.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16 gyp ERR! stack at C:\Users\Administrator\AppData\Roaming\nvm\v16.8.0\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7 gyp ERR! stack at C:\Users\Administrator\AppData\Roaming\nvm\v16.8.0\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16 gyp ERR! stack at ChildProcess.exithandler (node:child_process:404:5) gyp ERR! stack at ChildProcess.emit (node:events:394:28) gyp ERR! stack at maybeClose (node:internal/child_process:1064:16) gyp ERR! System Windows_NT 10.0.17763 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Administrator\\AppData\\Roaming\\nvm\\v16.8.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--module=D:\\DEV\\esop-front\\node_modules\\nodejieba\\build\\Release\\nodejieba.node" "--module_name=nodejieba" "--module_path=D:\\DEV\\esop-front\\node_modules\\nodejieba\\build\\Release" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93" "--python=python2.7" "--msvs_version=2017" gyp ERR! cwd D:\DEV\esop-front\node_modules\nodejieba gyp ERR! node -v v16.8.0 gyp ERR! node-gyp -v v7.1.2 gyp ERR! not ok node-pre-gyp ERR! build error node-pre-gyp ERR! stack Error: Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\Administrator\AppData\Roaming\nvm\v16.8.0\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --module=D:\DEV\esop-front\node_modules\nodejieba\build\Release\nodejieba.node --module_name=nodejieba --module_path=D:\DEV\esop-front\node_modules\nodejieba\build\Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93 --python=python2.7 --msvs_version=2017' (1) node-pre-gyp ERR! stack at ChildProcess.<anonymous> (D:\DEV\esop-front\node_modules\@mapbox\node-pre-gyp\lib\util\compile.js:89:23) node-pre-gyp ERR! stack at ChildProcess.emit (node:events:394:28) node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1064:16) node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) node-pre-gyp ERR! System Windows_NT 10.0.17763 node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\DEV\\esop-front\\node_modules\\@mapbox\\node-pre-gyp\\bin\\node-pre-gyp" "rebuild" node-pre-gyp ERR! cwd D:\DEV\esop-front\node_modules\nodejieba node-pre-gyp ERR! node -v v16.8.0 node-pre-gyp ERR! node-pre-gyp -v v1.0.5 node-pre-gyp ERR! not ok Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\Administrator\AppData\Roaming\nvm\v16.8.0\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --module=D:\DEV\esop-front\node_modules\nodejieba\build\Release\nodejieba.node --module_name=nodejieba --module_path=D:\DEV\esop-front\node_modules\nodejieba\build\Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93 --python=python2.7 --msvs_version=2017' (1)

網上的辦法都做了個遍,都不行,包括什麼清快取、刪node_modules、裝windows-build-tools等等,

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

後來發現,首先得解決python版本(https://www.python.org/downloads/)過低問題,然後安裝最新版的windows-build-tools。

最後把windows-build-tools版本和自己安裝的版本對應起來。

執行最後這句:

npm config set msvs_version 2019

大功告成!注意,後面的msvs_version要和你現在安裝好的版本一樣(2019)。網上寫的都是2017, 所以一直出錯。

參考版本:

winows10

python3.8

"nodejieba":"^2.5.2",

參考連結:

https://www.jianshu.com/p/e546464d6162

https://www.jianshu.com/p/4a45e115a626

https://stackoverflow.com/questions/65258925/how-to-fix-node-js-error-like-gyp-err-find-vs-including-the-desktop-developme