【问题标题】:Cannot run npm run serve无法运行 npm run serve
【发布时间】:2018-11-29 09:56:55
【问题描述】:

我为 vue 创建了一个客户端项目并运行 npm run serve, 但出现此错误:

尝试重新安装 node、npm,编辑了一些 PATH,但没有任何效果

版本

3.2.1

节点和操作系统信息

节点 v10.14.0/npm 6.4.1

    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.4.1
    3 info using node@v10.14.0
    4 verbose run-script [ 'preserve', 'serve', 'postserve' ]
    5 info lifecycle client@0.1.0~preserve: client@0.1.0
    6 info lifecycle client@0.1.0~serve: client@0.1.0
    7 verbose lifecycle client@0.1.0~serve: unsafe-perm in lifecycle true
    8 verbose lifecycle client@0.1.0~serve: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/alexsexotic/Desktop/work/Test - mongod:node/client/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Users/alexsexotic/.npm-global/bin
    9 verbose lifecycle client@0.1.0~serve: CWD: /Users/alexsexotic/Desktop/work/Test - mongod:node/client
    10 silly lifecycle client@0.1.0~serve: Args: [ '-c', 'vue-cli-service serve' ]
    11 info lifecycle client@0.1.0~serve: Failed to exec serve script
    12 verbose stack Error: client@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:182:13)
    12 verbose stack     at maybeClose (internal/child_process.js:962:16)
    12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
    13 verbose pkgid client@0.1.0
    14 verbose cwd /Users/alexsexotic/Desktop/work/Test - mongod:node/client
    15 verbose Darwin 17.2.0
    16 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "serve"
    17 verbose node v10.14.0
    18 verbose npm  v6.4.1
    19 error file sh
    20 error code ELIFECYCLE
    21 error errno ENOENT
    22 error syscall spawn
    23 error client@0.1.0 serve: `vue-cli-service serve`
    23 error spawn ENOENT
    24 error Failed at the client@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 ]

【问题讨论】:

  • 把你的问题美化一点,把更多的细节放在一边
  • 向我们展示你的 package.json,看看“scripts”字段中是否有“serve”
  • @javimovi 给你 { "name": "client", "version": "0.1.0", "private": true, "scripts": { "serve": "vue- cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint" },
  • 你能运行npx serve看看它是否有效吗?
  • @Aer0 哇,它有点工作,但我的 index.hmtl 没有加载,请问您如何看待这个解决方案?我搜索了很多论坛,但没有人为我解决。

标签: vue.js


【解决方案1】:

您可以检查您当前的 cli 安装,也可以重新安装您的 vue-cli。基本上,npx 命令在您的项目目录中运行。因此运行npx [whatever] 将始终使用安装在项目本身中的模块,而npm run [whatever] 可能会引用一些全局安装的依赖项。

也就是说,您也可以尝试使用 yarn。过去我在通过npm 运行 vue-cli 时也遇到了一些问题,所以我切换到了yarn

但是,对于您的index.html 问题,我无法为您提供帮助,因为这可能是另一个问题。但是如果你在整个 vue-cli 中引导了一个新的 vue 项目,它应该可以工作。

【讨论】:

  • 所以我需要在我的文件夹中安装 yarn 并运行 yarn serve?
  • 全局安装。它比npm 快得多,并且还具有更多功能。只需查看网站。它实际上与npm 相同 - 一个节点包管理器。
  • 现在我得到了这个错误: has-macbook-air:client alexsexotic$ yarn run serve yarn run v1.12.3 $ vue-cli-service serve /bin/sh: vue-cli-service: command未找到错误命令失败,退出代码为 127。信息访问yarnpkg.com/en/docs/cli/run 以获取有关此命令的文档。 has-macbook-air:client alexsexotic$
  • 好像你没有全局安装的 vue-cli 版本。您是否尝试重新安装它?否则我真的不知道了。对不起。
  • 经过2天的努力,我决定再次查看错误消息,并意识到用空格键命名文件夹不是一个好主意,所以我重命名它,它终于可以工作了
【解决方案2】:

你可以试试这个:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

这对我有用。

【讨论】:

    猜你喜欢
    • 2019-12-06
    • 2018-12-21
    • 2017-10-05
    • 2020-01-31
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    相关资源
    最近更新 更多