昨天,在克隆工作组存储库后,我发现一些非常奇怪的事情。使用npm install安装依赖项后,我无法在项目内启动devserver(或运行任何npm脚本)。奇怪。因此,我然后尝试使用@ vue / cli创建我自己的新项目,并且在那里发生了同样的事情。 环境: 节点:v14.15.0 NPM:v6.14.8 全局安装的Vue Cli:v4.5.8 macOS Catalina:v10.15.7
项目中的Package.json:
"name": "eezer_app",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuetify": "^2.2.11",
"vuex": "^3.4.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"sass": "^1.19.0",
"sass-loader": "^8.0.0",
"vue-cli-plugin-vuetify": "~2.0.7",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.3.0"
}
}
错误输出:
➜ eezer_app git:(master) ✗ npm run serve
> eezer_app@0.1.0 serve /Users/my-real-name/Documents/frontend-jensen/UX:UI-2/eezer_app
> vue-cli-service serve
sh: vue-cli-service: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! eezer_app@0.1.0 serve: `vue-cli-service serve`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the eezer_app@0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/my-real-name/.npm/_logs/2020-11-03T09_50_50_094Z-debug.log
调试日志文件:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'serve' ]
2 info using npm@6.14.8
3 info using node@v14.15.0
4 verbose run-script [ 'preserve', 'serve', 'postserve' ]
5 info lifecycle eezer_app@0.1.0~preserve: eezer_app@0.1.0
6 info lifecycle eezer_app@0.1.0~serve: eezer_app@0.1.0
7 verbose lifecycle eezer_app@0.1.0~serve: unsafe-perm in lifecycle true
8 verbose lifecycle eezer_app@0.1.0~serve: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/my-real-name/Documents/frontend-jensen/UX:UI-2/eezer_app/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle eezer_app@0.1.0~serve: CWD: /Users/my-real-name/Documents/frontend-jensen/UX:UI-2/eezer_app
10 silly lifecycle eezer_app@0.1.0~serve: Args: [ '-c', 'vue-cli-service serve' ]
11 info lifecycle eezer_app@0.1.0~serve: Failed to exec serve script
12 verbose stack Error: eezer_app@0.1.0 serve: `vue-cli-service serve`
12 verbose stack spawn ENOENT
12 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack at ChildProcess.emit (events.js:315:20)
12 verbose stack at maybeClose (internal/child_process.js:1048:16)
12 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
13 verbose pkgid eezer_app@0.1.0
14 verbose cwd /Users/my-real-name/Documents/frontend-jensen/UX:UI-2/eezer_app
15 verbose Darwin 19.6.0
16 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "serve"
17 verbose node v14.15.0
18 verbose npm v6.14.8
19 error code ELIFECYCLE
20 error syscall spawn
21 error file sh
22 error errno ENOENT
23 error eezer_app@0.1.0 serve: `vue-cli-service serve`
23 error spawn ENOENT
24 error Failed at the eezer_app@0.1.0 serve script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]
同样由vue create
创建的Vue项目中也出现了相同的错误。
npm似乎正在尝试全局查找依赖包,而不是在node_modules中本地查找依赖包,因为我可以通过在本地node_module .bin中手动选择脚本来运行服务,如下所示:
./node_modules/.bin/vue-cli-service serve
然后它可以完美启动,没有任何故障 ,因此已安装的node_modules等没有任何问题。从昨天开始,我尝试修复此问题,但没有结果。我找到了清除npm缓存,删除本地node_modules和package-lock.json的提示,但它根本不起作用。我什至在Mac上重新安装了CLT。
我的npm怎么了?为什么似乎要在我的全局node_module中寻找依赖关系?
自从我用尽了大多数选择之后,不胜感激任何技巧。
答案 0 :(得分:0)
我更新了 Node、NPM、我所有的全局节点模块,运行了 brew update
,重新安装了 xcode:sudo rm -rf /Library/Developer/CommandLineTools
然后 xcode-select --install
,它似乎又可以工作了。
在使用 vue create 创建的新创建的 Vue 项目中也出现了同样的错误。
使用@vue/cli 创建了一个全新的 vue 项目,并且我能够运行 npm run serve
。希望这对面临此问题的其他人有所帮助。