npm run server 抛出错误 sh: 1: vue-cli-service: not found
Posted
技术标签:
【中文标题】npm run server 抛出错误 sh: 1: vue-cli-service: not found【英文标题】:npm run server throws error sh: 1: vue-cli-service: not found 【发布时间】:2020-05-09 00:57:07 【问题描述】:我正在尝试设置现有的 vue 项目并收到此错误
admin@kali:/media/veracrypt1/themeforest-LSerfC0M-skote-vuejs-admin-dashboard-template/Admin$ npm run serve
> skote@0.1.0 serve /media/veracrypt1/themeforest-LSerfC0M-skote-vuejs-admin-dashboard-template/Admin
> vue-cli-service serve
sh: 1: vue-cli-service: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! skote@0.1.0 serve: `vue-cli-service serve`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the skote@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! /home/admin/.npm/_logs/2020-01-22T19_13_27_378Z-debug.log
在 Windows 上,我可以通过删除“node_modules”文件夹并重新安装它来解决它,但在 linux 中没有任何效果,删除它甚至重新安装依赖项。
以下是错误日志的内容
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'serve' ]
2 info using npm@6.13.4
3 info using node@v10.17.0
4 verbose run-script [ 'preserve', 'serve', 'postserve' ]
5 info lifecycle skote@0.1.0~preserve: skote@0.1.0
6 info lifecycle skote@0.1.0~serve: skote@0.1.0
7 verbose lifecycle skote@0.1.0~serve: unsafe-perm in lifecycle true
8 verbose lifecycle skote@0.1.0~serve: PATH: /usr/share/npm/node_modules/npm-lifecycle/node-gyp-bin:/media/veracrypt1/themeforest-LSerfC0M-skote-vuejs-admin-dashboard-template/Admin/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
9 verbose lifecycle skote@0.1.0~serve: CWD: /media/veracrypt1/themeforest-LSerfC0M-skote-vuejs-admin-dashboard-template/Admin
10 silly lifecycle skote@0.1.0~serve: Args: [ '-c', 'vue-cli-service serve' ]
11 info lifecycle skote@0.1.0~serve: Failed to exec serve script
12 verbose stack Error: skote@0.1.0 serve: `vue-cli-service serve`
12 verbose stack spawn ENOENT
12 verbose stack at ChildProcess.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack at ChildProcess.emit (events.js:198:13)
12 verbose stack at maybeClose (internal/child_process.js:982:16)
12 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
13 verbose pkgid skote@0.1.0
14 verbose cwd /media/veracrypt1/themeforest-LSerfC0M-skote-vuejs-admin-dashboard-template/Admin
15 verbose Linux 5.3.0-kali2-amd64
16 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "serve"
17 verbose node v10.17.0
18 verbose npm v6.13.4
19 error code ELIFECYCLE
20 error syscall spawn
21 error file sh
22 error errno ENOENT
23 error skote@0.1.0 serve: `vue-cli-service serve`
23 error spawn ENOENT
24 error Failed at the skote@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 ]
【问题讨论】:
这是一个重复的问题。 check this post 【参考方案1】:确保npm install
在npm i @vue/cli
之后,特别是如果你有Typescript。
安装@vue/cli
后可能需要额外的Typescript库。
【讨论】:
这实际上是 m.f 的答案对我有用的原因。【参考方案2】:删除 node_modules
文件夹和 package-lock.json
文件并运行新的 npm install 对我有用。
rm -rf node_modules package-lock.json && npm install
(在这里找到解决方案:https://github.com/vuejs/vue-cli/issues/2404#issuecomment-443397971)
注意
如果移动到不同/新的操作系统环境 - 也可能是没有安装 vue-cli,然后按照 official guide 中的说明安装 vue-cli。
【讨论】:
【参考方案3】:试试这个:
用npm uninstall -g @vue/cli
卸载vue/cli
用npm install -g @vue/cli
再次安装vue/cli(你也可以用sudo试试,比如sudo npm install -g @vue/cli
)
vue
【讨论】:
我正在使用kali linux,似乎某些依赖项不支持它,它正在寻找发行版类型:darwin。【参考方案4】:运行:
npm i @vue/cli-service
那是因为你的依赖没有安装。
【讨论】:
以上是关于npm run server 抛出错误 sh: 1: vue-cli-service: not found的主要内容,如果未能解决你的问题,请参考以下文章
Laravel 项目中的“npm run hot”抛出无效配置错误
POST 方法在 npm http-server 上抛出错误 405
使用 Github Actions 发布 React+dotnet 核心应用程序抛出错误 MSB3073: The command "npm run build" exited w
npm run serve 给出错误 sh: vue-cli-service: command not found in Vue Cli app