3

Our production environment have to using "npm install --production" to install the project, but when trigger "npm run serve" that encounter Below error:

'vue-cli-service' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1

Here is the command sequence :

  1. npm install --production
  2. npm run serve

Below is the package.json

{
  "name": "xxxxxx",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "bootstrap": "^4.4.1",
    "bootstrap-vue": "^2.7.0",
    "core-js": "^3.4.3",
    "vue": "^2.6.11",
    "vue-router": "^3.1.3"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.1.0",
    "@vue/cli-plugin-eslint": "^4.1.0",
    "@vue/cli-service": "^4.1.0",
    "babel-eslint": "^10.0.3",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.0.0",
    "vue-template-compiler": "^2.6.11"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {
      "no-console": "off"
    },
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
  "browserslist": [
    "> 1%",`enter code here`
    "last 2 versions"
  ]
}

Could anyone help on this case ? Many thanks...

John Jin
  • 125
  • 1
  • 8

1 Answers1

1

Does the serve script require your devDependencies? If you run npm install then npm run serve does it work?

Can you run vue --version from your prod environment? That error makes me think the whole @vue/cli global install is missing.

Post may be a dupe: How to solve 'vue-cli-service' is not recognized as an internal or external command?

Just in case, you may want to rm -rf node_modules then install, then serve.

amishpanda
  • 91
  • 1
  • 8
  • I run npm install then npm run serve it will work. But using "'npm install --production'' even in my local.In Visual studio code run vue --version show this : PS D:\xx\app> vue --version vue : File C:\Users\jinjo2\AppData\Roaming\npm\vue.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1 + vue --version + ~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess – John Jin Mar 28 '20 at 03:01
  • "With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies." Sounds like this is working as intended then. I think the expected deploy to production is to make a distribution of javascript + html files. Then those are served up by a webserver, not "npm run serve". If you intend to use the "serve" script it relies on devDependencies in your `package.json`, thus it won't work if you use the --production flag. That's my guess. – amishpanda Mar 28 '20 at 18:08
  • Yes, when using --production flag it won't build with devDependencies, but even I add "@vue/cli-service": "^4.1.0" into dependencies but still cannot success to run 'npm run serve' and throw 'vue-cli-service' is not recognized as an internal or external command error message. – John Jin Mar 31 '20 at 01:16