記錄一次vue的啟動
以下步驟在管理員權限下執行
安裝node.js
網上一堆
idea安裝vue.js插件
過於簡單
安裝vue-cli
npm install -g vue-cli
構建項目(已經有項目忽略這一步)
vue init webpack frontend
安裝項目依賴
需要切換到項目根目錄下,有個package.json,直接使用npm install
命令就可以識別安裝
這一步經常出問題
如果出問題了,不要慌,下面給出我遇到的問題的坑:
需要python2.7
第一次運行出錯:
根據提示查看日志文件:
之后在日志文件中發現
3796 error gyp verb check python checking for Python executable "python2" in the PATH
3796 error gyp verb which
failed Error: not found: python2
雖然不知道為什么需要python的上古時代的2.0技術,但是還必須要按照提示安裝
http://dragon.feisir.top:5244/d/small/軟件/編程/python/python-2.7.2.amd64.msi
點擊下載安裝即可,選擇默認安裝路徑,這樣不會影響python3.0+體系。
使用這條命令將npm指向python2.7
npm config set python python2.7
刪除node-moduls重來
使用國內鏡像下載
npm set registry https://registry.npm.taobao.org
# 注冊模塊鏡像
npm set disturl https://npm.taobao.org/dist # node-gyp
編譯依賴的 node 源碼鏡像
npm cache clean --force
# 清空緩存
npm install -g cnpm --registry=https://registry.npm.taobao.org
# 安裝cnpm
執行cnpm install出現錯誤
gyp ERR! This is a bug in node-gyp
.
gyp ERR! Try to update node-gyp and file an Issue if it does not help:
gyp ERR! https://github.com/nodejs/node-gyp/issues
Build failed with error code: 7
[npminstall:runscript:error] node-sass@^4.14.1 scripts.postinstall run "node scripts/build.js" error: Error [RunScriptError]: Run "C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js" error, exit code 1
at ChildProcess.
at ChildProcess.emit (node:events:520:28)
at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) {
stdio: [Object],
exitcode: 1
}
× Install fail! RunScriptError: post install error, please remove node_modules before retry!
Run "C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js" error, exit code 1
RunScriptError: Run "C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js" error, exit code 1
at ChildProcess.
at ChildProcess.emit (node:events:520:28)
at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
這個錯誤給了兩個提示(加粗部分)
- 嘗試升級node-gyp,如果沒有效果的話訪問https://github.com/nodejs/node-gyp/issues去尋找解決辦法
- 刪除node-moduls,再次嘗試install
首先試了一下刪除node-moduls再次嘗試cnpm install
代理問題
出現同樣的錯誤,刪除node-moduls嘗試npm install
提示不讓通過代理下載,設置禁止使用代理
npm config set proxy false
關閉代理,npm cache verify
使緩存生效。
清除node-moduls文件繼續。還是失敗,同樣的錯誤!!
node-gyp升級
看來只有升級node-gyp了,既然都折騰了這么久,不如了解下node-gyp到底是個啥,引用知乎上的回答
要理解node-gyp首先要知道什么是gyp(https://gyp.gsrc.io/index.md)。gyp其實是一個用來生成項目文件的工具,一開始是設計給chromium項目使用的,后來大家發現比較好用就用到了其他地方。生成項目文件后就可以調用GCC, vsbuild, xcode等編譯平台來編譯。至於為什么要有node-gyp,是由於node程序中需要調用一些其他語言編寫的工具甚至是dll,需要先編譯一下,否則就會有跨平台的問題,例如在windows上運行的軟件copy到mac上就不能用了,但是如果源碼支持,編譯一下,在mac上還是可以用的。
所以這樣一來就解釋清楚了為什么前面需要python了,就是為了編譯一些東西,至於為什么是2.0的那就不得而知了
接下來看看提示給出的網頁https://github.com/nodejs/node-gyp/issues會給出什么答案:
經過一番尋找,終於找到一個相似的問題https://github.com/nodejs/node-gyp/issues/2366
來看看他遇到的錯誤
在這里看見了相似的錯誤,於是當下決定一探究竟
在這里看見了原作者的回答
讓升級后再試試,我們按照提示來做
npm install --global --production windows-build-tools
安裝windows下各語言的編譯工具包(其實一般最新的node.js中有)
npm install -g node-gyp
單獨安裝node-gpy(用這條命令就可以,不用使用最新版的。)
npm install --global node-gyp@latest
安裝最新版node-gpy
最后成功::
運行項目
項目根目錄下,使用npm run server
即可
大功告成!!!!