繁体   English   中英

npm run serve 给出错误 sh: vue-cli-service: command not found in Vue Cli app

[英]npm run serve gives error sh: vue-cli-service: command not found in Vue Cli app

昨天克隆我的工作组存储库后,我注意到一些非常奇怪的事情。 使用 npm install 安装依赖项后,我无法在项目中启动 devserver(或运行任何 npm 脚本)。 奇怪的。 于是我尝试用 @vue/cli 创建我自己的新项目,同样的事情发生在那里。 环境: Node: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 中寻找依赖项?

感谢任何类型的提示,因为我已经用尽了我的大部分选择。

我更新了 Node、NPM、我所有的全局节点模块,运行了brew update ,重新安装了 xcode: sudo rm -rf /Library/Developer/CommandLineTools然后xcode-select --install ,它似乎又开始工作了。

同样的错误也出现在使用 vue create 创建的新创建的 Vue 项目中。

使用 @vue/cli 创建了一个新的 vue 项目,我能够运行npm run serve 希望这对面临此问题的其他人有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM