error "vue-cli-service: command not found" when running a Vue app

Viewed 8111

If I execute the following commands from the root of my Vue app (v. 2.6.12)

rm -rf node_modules
npm install
npm run serve

I get the following error

sh: vue-cli-service: command not found

If I manually add the following symlink to node_modules/.bin the error does not occur

vue-cli-service -> ../@vue/cli-service/bin/vue-cli-service.js

But I shouldn't have to do this manually, i.e. if this symlink is required, it should be created when the @vue/cli-service package is installed.

I'm using NPM version 7.0.3 and have the following declared in the devDependencies section of package.json

"@vue/cli-service": "^4.5.6"
4 Answers

You may be able to skirt the issue by using the following in your package.json:

"serve": "./node_modules/.bin/vue-cli-service serve"

OR

"serve": "node ./node_modules/@vue/cli-service/bin/vue-cli-service.js serve"

This is just a temporary fix, though, as it is most likely an issue with npm not setting the correct path or npm not installing the binary properly. Try upgrading npm and nvm. See @bravemaster's comment on the github issue, as this contains several potential fixes.

npm install worked for me in the past, but check the package.json, which should roughly like this:

"scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
},
...
"devDependencies": {
    ...
    "@vue/cli-service": "~4.5.0",
    ...
},

Vue cli must be installed with global flag.

npm install -g vue-cli-service

If error try same command with sudo.

Vue-cli should not be in your package.json as a dependency (not even in dev-dependencies) because it is used only to generate a new project from scratch, not being necessary to run/server/build a project. (in dev or production), as the scripts are set in scripts section from package.json.

Replacing NPM with Yarn 1.X resolved this issue

Related