赞
踩
昨天一趟就配好了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 socks@1.1.10: 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
- + cnpm@6.0.0
- 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\_chromedriver@2.44.1@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] mkdirp@^0.5.1 installed at node_modules\_mkdirp@0.5.1@mkdirp
- [2/5] tcp-port-used@^1.0.1 installed at node_modules\_tcp-port-used@1.0.1@tcp-port-used
- [3/5] extract-zip@^1.6.7 installed at node_modules\_extract-zip@1.6.7@extract-zip
- [4/5] del@^3.0.0 installed at node_modules\_del@3.0.0@del
- [5/5] request@^2.88.0 installed at node_modules\_request@2.88.0@request
- execute post install 1 scripts...
- [1/1] scripts.install chromedriver@2.44.1 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 chromedriver@2.44.1 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)
- [chromedriver@2.44.1] link C:\toolkit\node-v10.14.1-win-x64\chromedriver@ -> 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
-
- > yanyan@1.0.0 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
-
- > yanyan@1.0.0 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
没踩完的坑明天接着踩。。。。。。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。