无法运行NPM运行服务

时间:2018-11-29 09:56:56

标签: vue.js

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

试图重新安装节点npm,编辑了一些PATHS,但没有任何作用

版本

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 ]

2 个答案:

答案 0 :(得分:0)

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

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

但是,关于您的index.html问题,我无能为力,因为这可能是另一个问题。但是,如果您在整个vue-cli中启动了一个新的vue项目,它应该可以工作。

答案 1 :(得分:0)

您可以尝试以下方法:

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

这对我有用。