npm install vue-cli -g vue init webpack project-name cd project-name npm install npm run dev
报错处理
在使用CSDN的codechina做仓库,用Hbuilder拉时报错,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
➜ demoTest git:(master) npm run dev
> test@1.0.0 dev /Users/dragonone/Desktop/VueProject/demoTest > webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
sh: webpack-dev-server: command not found npm ERR! code ELIFECYCLE npm ERR! syscall spawn npm ERR! file sh npm ERR! errno ENOENT npm ERR! test@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js` npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the test@1.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in: npm ERR! /usr/local/bin/node_package/node_cache/_logs/2021-11-22T12_08_36_738Z-debug.log
解决办法:
1 2
npm uninstall webpack-dev-server npm i webpack-dev-server@2.9.7
针对在上述安装vue-cli过程中可能出现的报错问题。报错信息借网上一用。其实都差不多。
1 2 3 4 5 6 7 8 9 10
npm ERR! code EEXIST npm ERR! path D:\nodejs\node_globalnpm\node_modules\@vue\cli\bin\vue.js npm ERR! dest D:\nodejs\node_globalnpm\vue npm ERR! EEXIST: file already exists, cmd shim 'D:\nodejs\node_globalnpm\node_modules\@vue\cli\bin\vue.js' -> 'D:\nodejs\node_globalnpm\vue' npm ERR! File exists: D:\nodejs\node_globalnpm\vue npm ERR! Remove the existing file and try again, or run npm npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in: npm ERR! D:\Program Files\nodejs\node_cache\_logs\2021-01-25T07_14_17_763Z-debug.log
在运行一些 vue 项目的时候,输入npm run serve或者 npm run dev的其中一个时,系统会报错,类似如下:
1 2 3 4 5 6
PS C:\Users\LENOVO\Desktop> npm run dev npm ERR! missing script: dev
npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\LENOVO\AppData\Roaming\npm-cache\_logs\2020-05-27T01_05_59_189Z-debug.log PS C:\Users\LENOVO\Desktop\website> npm run serve
所以,到底什么时候用npm run dev、什么时候用npm run serve。这其实都是同一个东西,只是名字换了一个而已。
可以把这个 npm run serve 当做是 npm run package.json 里面的scripts的serve,而serve又表示vue-cli-service serve 。所以npm run serve 实际运行的是 vue-cli-service serve;而如果你想使用npm run dev 的话,只需把前面的 “serve” 修改为 “dev” 就行。如下: