第一步:檢查和安裝?
我這里建議檢查
1.node.js版本是否和前使用版本一致
2.npm版本是否和前使用版本一致
3.vue版本是否和前使用版本一致
4.vue腳手架是否和前使用版本一致
5.npm鏡像是否和前使用版本一致
?1.檢查版本
【node版本】
命令:node -v
結(jié)果:v16.13.0 (我目前使用的版本)
【npm版本】
命令:npm -v
結(jié)果:8.1.0
【cnpm版本】
命令:cnpm -v
結(jié)果:cnpm@6.1.1
【npm映射網(wǎng)址(鏡像網(wǎng)址)】
命令:npm config get registry
結(jié)果:https://registry.npmjs.org/ (我這里是官方默認(rèn)鏡像)
【vue腳手架版本】
命令:vue -V
結(jié)果:
@vue/cli 4.5.6
"vue": "^2.5.2",
?2.安裝版本
【安裝指定版本的vue,需要卸載最新版本的vue】
npm uninstall -g @vue/cli
【安裝指定的vue版本腳手架】
npm install -g @vue/cli@4.5.6
【安裝指定的vue版本】
npm install vue@2.x.x
第二步:查看鏡像源配置
1.查看當(dāng)前使用的鏡像地址:
npm config get registry
2.官方默認(rèn)全局鏡像
https://registry.npmjs.org
3.設(shè)置鏡像源:
npm config set registry https://registry.npm.taobao.org
4.官方默認(rèn)全局鏡像
https://registry.npmjs.org
5.給項(xiàng)目單獨(dú)配置npm鏡像源
項(xiàng)目根目錄的 .npmrc 的配置,優(yōu)先級(jí)最高,且隨著項(xiàng)目一起,可以免去因不同開發(fā)者的電腦的環(huán)境配置不同而導(dǎo)致的依賴下載異常的問(wèn)題;實(shí)際開發(fā)中也推薦在根目錄下配置一份,可以給每個(gè)項(xiàng)目配置不同的鏡像,項(xiàng)目之間的配置互不影響。
.npmrc文件中寫如下內(nèi)容:
# 配置 npm 的默認(rèn)鏡像源為淘寶鏡像源
registry = "https://registry.npm.taobao.org"
6.常用鏡像源
# 淘寶鏡像源
https://registry.npmmirror.com
https://registry.npm.taobao.org
# 騰訊云鏡像源
http://mirrors.cloud.tencent.com/npm/
# 華為云鏡像源
https://mirrors.huaweicloud.com/repository/npm/
# 官方默認(rèn)全局鏡像
https://registry.npmjs.org
第三步:初始化項(xiàng)目
npm install
1.初始化報(bào)錯(cuò)
D:\projects\項(xiàng)目目錄>npm install
npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated acorn-dynamic-import@2.0.2: This is probably built in to whatever tool you're using. If you still need it... idk
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated consolidate@0.14.5: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog
npm WARN deprecated html-webpack-plugin@2.30.1: out of support
npm WARN deprecated extract-text-webpack-plugin@3.0.2: Deprecated. Please use https://github.com/webpack-contrib/mini-css-extract-plugin
npm WARN deprecated shvl@2.0.3: older versions vulnerable to prototype pollution
npm WARN deprecated vuex-persistedstate@4.1.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated uglify-es@3.3.9: support for ECMAScript is superseded by `uglify-js` as of v3.13.0
npm WARN deprecated bfj-node4@5.3.1: Switch to the `bfj` package for fixes and new features!
npm WARN deprecated svgo@0.7.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path D:\projects\項(xiàng)目目錄\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:\Program Files\nodejs\node.exe D:\projects\項(xiàng)目目錄\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli 'C:\\Program Files\\nodejs\\node.exe',
npm ERR! gyp verb cli 'D:項(xiàng)目目錄node_modules\\node-gyp\\bin\\node-gyp.js',
npm ERR! gyp verb cli 'rebuild',
npm ERR! gyp verb cli '--verbose',
npm ERR! gyp verb cli '--libsass_ext=',
npm ERR! gyp verb cli '--libsass_cflags=',
npm ERR! gyp verb cli '--libsass_ldflags=',
npm ERR! gyp verb cli '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@16.13.0 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb find Python Python is not set from command line or npm configuration
npm ERR! gyp verb find Python Python is not set from environment variable PYTHON
npm ERR! gyp verb find Python checking if "python3" can be used
npm ERR! gyp verb find Python - executing "python3" to get executable path
npm ERR! gyp verb find Python - "python3" is not in PATH or produced an error
npm ERR! gyp verb find Python checking if "python" can be used
npm ERR! gyp verb find Python - executing "python" to get executable path
npm ERR! gyp verb find Python - executable path is "C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\python.exe"
npm ERR! gyp verb find Python - executing "C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\python.exe" to get version
npm ERR! gyp verb find Python - version is "3.8.5"
npm ERR! gyp info find Python using Python version 3.8.5 found at "C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\python.exe"
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 16.13.0
npm ERR! gyp verb command install [ '16.13.0' ]
npm ERR! gyp verb install input version string "16.13.0"
npm ERR! gyp verb install installing version: 16.13.0
npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed
npm ERR! gyp verb install version is already installed, need to check "installVersion"
npm ERR! gyp verb got "installVersion" 9
npm ERR! gyp verb needs "installVersion" 9
npm ERR! gyp verb install version is good
npm ERR! gyp verb get node dir target node version installed: 16.13.0
npm ERR! gyp verb build dir attempting to create "build" dir: D:\projects\項(xiàng)目目錄\node_modules\node-sass\build
npm ERR! gyp verb build dir "build" dir needed to be created? D:\projects\項(xiàng)目目錄\node_modules\node-sass\build
npm ERR! gyp verb find VS msvs_version not set from command line or npm config
npm ERR! gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp verb find VS checking VS2017 (15.9.28307.1216) found at:
npm ERR! gyp verb find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise"
npm ERR! gyp verb find VS - found "Visual Studio C++ core features"
npm ERR! gyp verb find VS - missing any VC++ toolset
npm ERR! gyp verb find VS could not find a version of Visual Studio 2017 or newer to use
npm ERR! gyp verb find VS looking for Visual Studio 2015
npm ERR! gyp verb find VS - not found
npm ERR! gyp verb find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS checking VS2017 (15.9.28307.1216) found at:
npm ERR! gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise"
npm ERR! gyp ERR! find VS - found "Visual Studio C++ core features"
npm ERR! gyp ERR! find VS - missing any VC++ toolset
npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack at VisualStudioFinder.fail (D:\projects\項(xiàng)目目錄\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
npm ERR! gyp ERR! stack at D:\projects\項(xiàng)目目錄\node_modules\node-gyp\lib\find-visualstudio.js:74:16
npm ERR! gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (D:\projects\項(xiàng)目目錄\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
npm ERR! gyp ERR! stack at D:\projects\項(xiàng)目目錄\node_modules\node-gyp\lib\find-visualstudio.js:70:14
npm ERR! gyp ERR! stack at D:\projects\項(xiàng)目目錄\node_modules\node-gyp\lib\find-visualstudio.js:372:16
npm ERR! gyp ERR! stack at D:\projects\項(xiàng)目目錄\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack at D:\projects\項(xiàng)目目錄\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:404:5)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:390:28)
npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1064:16)
npm ERR! gyp ERR! System Windows_NT 10.0.18362
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:項(xiàng)目目錄node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd D:\projects\項(xiàng)目目錄\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.13.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\cpeng\AppData\Local\npm-cache\_logs\2023-10-28T06_05_05_750Z-debug.log
D:\projects\項(xiàng)目目錄>
2.清理緩存
npm cache clean --force
運(yùn)行后提示
npm WARN using --force Recommended protections disabled.
意思是?
npm WARN using——force禁用推薦保護(hù)。
繼續(xù)執(zhí)行下面命令
npm cache verify
刪除 “node_modules”文件夾,重新安裝,運(yùn)行
npm install
此時(shí)我的安裝還是報(bào)錯(cuò) ,錯(cuò)誤和上面一致。
原本我想著他總是說(shuō) 【node-sass】的問(wèn)題
npm ERR! path D:\projects\項(xiàng)目目錄\node_modules\node-sass
我根據(jù)【package.json】文件里的
"node-sass": "^6.0.1",
想著單獨(dú)安裝下“node-sass”,下面命令的意思是,安裝“node-sass”版本號(hào)是6.0.1
npm i node-sass@6.0.1
結(jié)果安裝后還是報(bào)錯(cuò),和上面的錯(cuò)誤一致
3.我開始懷疑是下面的這個(gè)錯(cuò)誤引起的
npm ERR! gyp verb find Python Python is not set from command line or npm configuration
npm ERR! gyp verb find Python Python is not set from environment variable PYTHON
npm ERR! gyp verb find Python checking if "python3" can be used
npm ERR! gyp verb find Python - executing "python3" to get executable path
npm ERR! gyp verb find Python - "python3" is not in PATH or produced an error
npm ERR! gyp verb find Python checking if "python" can be used
npm ERR! gyp verb find Python - executing "python" to get executable path
npm ERR! gyp verb find Python - executable path is "C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\python.exe"
npm ERR! gyp verb find Python - executing "C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\python.exe" to get version
npm ERR! gyp verb find Python - version is "3.8.5"
npm ERR! gyp info find Python using Python version 3.8.5 found at "C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\python.exe"
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 16.13.0
譯文
npm ERR!gyp謂詞find Python Python不是從命令行或npm配置中設(shè)置的
npm ERR!gyp動(dòng)詞find Python Python不是從環(huán)境變量Python中設(shè)置的
npm ERR!gyp動(dòng)詞find Python檢查是否可以使用“python3”
npm ERR!gyp動(dòng)詞find Python-執(zhí)行“python3”以獲取可執(zhí)行路徑
npm ERR!gyp動(dòng)詞find Python-“python3”不在PATH中或產(chǎn)生錯(cuò)誤
npm ERR!gyp動(dòng)詞find Python檢查是否可以使用“Python”
npm ERR!gyp動(dòng)詞find Python-執(zhí)行“Python”以獲取可執(zhí)行路徑
npm ERR!gyp動(dòng)詞find Python-可執(zhí)行路徑為“C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\Python.exe”
npm ERR!gyp動(dòng)詞查找Python-執(zhí)行“C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\Python.exe”以獲取版本
npm ERR!gyp動(dòng)詞find Python-版本為“3.8.5”
npm ERR!gyp info使用Python版本3.8.5查找Python,位于“C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\Python.exe”
npm ERR!gyp謂詞get node dir no--target
因?yàn)槲蚁到y(tǒng)之前裝了python??
下面命令的意思是 修改 npm的python命令指向,我安裝的python
npm config set python C:\Users\cpeng\AppData\Local\Programs\Python\Python38-32\python.exe
?查看?python路徑
我的電腦》屬性》高級(jí)系統(tǒng)設(shè)置》高級(jí)》環(huán)境變量
用戶變量》Path(選定這個(gè))》點(diǎn)擊“編輯”》就可以看到Python的安裝地址了
第四步:怎么刪除node_modules
1、安裝npm包–rimraf,很小的一個(gè)工具包
npm install rimraf -g
2、在cmd指令下,進(jìn)入所需刪除的node_modules文件夾的位置(路徑)
或
在VScode等開發(fā)工具的終端進(jìn)入到對(duì)應(yīng)位置(路徑)
3、輸入以下指令進(jìn)行刪除
rimraf node_modules
這樣就可以快捷且方便地刪除到node_modules啦!
最后:說(shuō)說(shuō)是怎么解決的
1.我卸載了我電腦的python ,然后重啟的電腦
2.清理緩存
使用【第三步】的2清理緩存
3.檢查了npm的鏡像
請(qǐng)看【第二步】
4.設(shè)置成淘寶鏡像源
請(qǐng)看【第二步】
5.刪除node_modules
快速刪除,請(qǐng)看【第四步】
6.執(zhí)行安裝命令
npm install --save
7.執(zhí)行運(yùn)行命令
npm run dev
就成功啟動(dòng)項(xiàng)目了
?老師的解惑
老師博客地址:全棧ACE的個(gè)人空間-全棧ACE個(gè)人主頁(yè)-嗶哩嗶哩視頻
我:
老師 我設(shè)置 npm的鏡像源地址為淘寶的鏡像后, ?我的npm 指令 走的就是淘寶了嗎?
ACE老師:
不是
它就相當(dāng)于它的這個(gè)安裝包放在國(guó)內(nèi)還是國(guó)外,國(guó)內(nèi)的話就放在淘寶的服務(wù)器里面,所以稱之為淘寶鏡像源
安裝插件的時(shí)候,它的地址都是在淘寶的服務(wù)器里。所以我們安裝的速度就很快。
如果不配置鏡像源,他是在國(guó)外那么下載起來(lái)就很慢。
我:
我一直以為,淘寶鏡像https://registry.npm.taobao.org是鏡像https://registry.npmjs.org的內(nèi)容;類似于cdn加速一樣
我理解錯(cuò)了
謝謝 老師解惑
?
以上截圖內(nèi)容,都是ace老師視頻,且視頻都是免費(fèi)觀看;
ace老師這個(gè)人很“極客”,
作者希望,感興趣的有緣人,有空可以去看看,來(lái)增加自己的知識(shí)儲(chǔ)備量。
另外,感恩ACE老師無(wú)償分享文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-721535.html
地址:全棧ACE的個(gè)人空間-全棧ACE個(gè)人主頁(yè)-嗶哩嗶哩視頻?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-721535.html
到了這里,關(guān)于npm install報(bào)錯(cuò),解決記錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!