1. 程式人生 > >npm常見錯誤總結

npm常見錯誤總結

昨天一趟就配好了vue,該配的都配好了,今天早上一開啟就不對勁了,一步一步改錯終於改完了,感覺真是把能踩的坑都給踩了,下面我以我改錯的過程為序總結一下npm常見的錯誤。

一,昨天是用cmder.zip解壓後配的,但今天感覺這個東西並沒有那麼好用,要在settings裡面配好多東西煩的很,還不如直接用win+R產生的cmd命令視窗中配置。

​
C:\Users\Administrator>D:

D:\>cd work

D:\work>

​

1.不知道咋回事,今天建立新專案,老出現npm error的錯,無奈之下我把D盤的toolkit目錄和work目錄全部清空,把C:\Users\Administrator下的.config,.npminstall_tarball,.vue-templates清空,把AppData下的和npm有關的所有檔案都給刪掉,然後在D盤下重新建立toolkit資料夾和work資料夾,然後將下載好的node-v10.14.2-win-x64.zip重新解壓到work資料夾下。即重新安裝node。

2.開啟cmd,安裝cnpm:npm install -g cnpm --registry=https://registry.npm.taobao.org

此命令是安裝淘寶映象,由於npm中的許多包都是在國外,安裝起來特別慢,為了能夠加快安裝速度,所以需要利用國內的像伺服器。地址為 https://npm.taobao.org 。然後後面的命令我們可以用cnpm 來替代 npm 。

npm install -g cnpm --registry=https://registry.npm.taobao.org
X:\work
λ npm install -g cnpm --registry=https://registry.npm.taobao.org
npm WARN deprecated 
[email protected]
: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0 C:\toolkit\node-v10.14.1-win-x64\cnpm -> C:\toolkit\node-v10.14.1-win-x64\node_modules\cnpm\bin\cnpm + [email protected] added 635 packages from 845 contributors in 63.012s

3.安裝webpack :

cnpm install -g webpack

-g表示全域性安裝

4.安裝vue-cli :

cnpm install --global vue-cli

這樣安裝之後,如果目前安裝正確的話就好,如果報chromedrive沒有安裝的錯那就說明用這個命令來安裝chromedriver(即vue-cli)是不對的,此時我們輸入以下命令:

cnpm install chromedriver -g

然後出現這個:

D:\work
λ cnpm install chromedriver -g
Downloading chromedriver to C:\toolkit\node-v10.14.1-win-x64\node_modules\chromedriver_tmp
Copying C:\toolkit\node-v10.14.1-win-x64\node_modules\chromedriver_tmp\[email protected]@chromedriver to C:\toolkit\node-v10.14.1-win-x64\node_modules\chromedriver
Installing chromedriver's dependencies to C:\toolkit\node-v10.14.1-win-x64\node_modules\chromedriver/node_modules
[1/5] [email protected]^0.5.1 installed at node_modules\[email protected]@mkdirp
[2/5] [email protected]^1.0.1 installed at node_modules\[email protected]@tcp-port-used
[3/5] [email protected]^1.6.7 installed at node_modules\[email protected]@extract-zip
[4/5] [email protected]^3.0.0 installed at node_modules\[email protected]@del
[5/5] [email protected]^2.88.0 installed at node_modules\[email protected]@request
execute post install 1 scripts...
[1/1] scripts.install [email protected] run "node install.js"
Current existing ChromeDriver binary is unavailable, proceding with download and extraction.
Downloading from file:  https://cdn.npm.taobao.org/dist/chromedriver/2.44/chromedriver_win32.zip
Saving to file: C:\Users\ADMINI~1\AppData\Local\Temp\chromedriver\chromedriver_win32.zip
Received 782K...
Received 1563K...
Received 2345K...
Received 3127K...
Received 3909K...
Received 4467K total.
Extracting zip contents
Copying to target path C:\toolkit\node-v10.14.1-win-x64\node_modules\chromedriver\lib\chromedriver
Done. ChromeDriver binary available at C:\toolkit\node-v10.14.1-win-x64\node_modules\chromedriver\lib\chromedriver\chromedriver.exe
[1/1] scripts.install [email protected] finished in 2s
All packages installed (98 packages installed from npm registry, used 6s(network 4s), speed 409.05kB/s, json 93(155.72kB), tarball 1.27MB)
[[email protected]] link C:\toolkit\node-v10.14.1-win-x64\[email protected] -> C:\toolkit\node-v10.14.1-win-x64\node_modules\chromedriver\bin\chromedriver

5.建立專案:vue init webpack my-project,這裡的my-project指的是我要建立的專案的名字。

vue init webpack yanyan

6.安裝專案依賴 :

D:\work\yanyan>cnpm install

出現下面的程式碼說明安裝正確 

D:\work\yanyan>cnpm install
√ Installed 69 packages
√ Linked 0 latest versions
√ Run 0 scripts
√ All packages installed (used 516ms(network 510ms), speed 0B/s, json 0(0B), tarball 0B)

7.執行專案 : npm run dev

D:\work\yanyan>cnpm run dev

此時出現了dev不存在的錯,missing script:dev是因為路徑不對,是D盤下的work下的yanyan

C:\Users\Administrator>D:

D:\>cd work

D:\work>cd yanyan
D:\work\yanyan>cnpm run dev
D:\work\yanyan>cnpm run dev

> [email protected] dev D:\work\yanyan
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

 95% emitting

 DONE  Compiled successfully in 22147ms                                                                         16:56:46
 I  Your application is running here: http://localhost:8080

8.npm install 報錯不存在package.json,在路徑中找不到package.json檔案,首先初始化,再安裝相應的檔案

 1.  npm init -f //強迫初始化檔案
 2.  npm install bluebird --save
-f表示force的意思,不加這個,npm會讓你輸入一堆資訊,比如name、version之類,如果只是做做實驗小demo,直接-f,npm幫你初始化package.json,並填充各種預設值,省事。

–save表示將安裝的包加入依賴列表的意思,可以看下package.json 裡的dependencies欄位。後面再執行 npm install,就會把所有依賴安裝下來。如果不加–save,什麼都不會安裝。
這個方法是我在這個部落格裡看到的:https://blog.csdn.net/a_bet_of_three_years/article/details/82120393,說的很好。

9.npm install 報錯(npm ERR! errno -4048,Error: EPERM: operation not permitted,)這個錯不是許可權的問題。

10.最後出現了一個錯(This is probably not a problem with npm. There is likely additional logging output above.)這可能不是npm的問題。上面可能還有其他日誌輸出。此時關掉cmd,重新開啟cmd

C:\Users\Administrator>D:

D:\>cd work

D:\work>cd yanyan

D:\work\yanyan>ls -la
'ls' 不是內部或外部命令,也不是可執行的程式
或批處理檔案。

D:\work\yanyan>cnpm install
√ Installed 69 packages
√ Linked 0 latest versions
√ Run 0 scripts
√ All packages installed (used 516ms(network 510ms), speed 0B/s, json 0(0B), tarball 0B)

D:\work\yanyan>cnpm run dev

> [email protected] dev D:\work\yanyan
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

 95% emitting

 DONE  Compiled successfully in 22147ms                                                                         16:56:46
 I  Your application is running here: http://localhost:8080

沒踩完的坑明天接著踩。。。。。。