如何解决 vue-cli-service: not found proplem on heroku?

Lam*_*oss 5 heroku node.js vue-cli

我在尝试部署名为 tr3 的应用程序时遇到问题(它在本地主机上运行良好,而且我还学会了使用 heroku 部署“测试应用程序”,一切都很好)。但是现在,当我使用命令时

git push heroku master

有一条消息

remote: -----> Compressing...
remote:        Done: 22.2M
remote: -----> Launching...
remote:        Released v8
remote:        https://stark-oasis-45806.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/stark-oasis-45806.git
   12055ef..fbc5e05  master -> master
Run Code Online (Sandbox Code Playgroud)

但是链接https://stark-oasis-45806.herokuapp.com/会导致错误

020-06-19T17:42:19.575287+00:00 app[web.1]: > tr3@0.1.0 start /app
2020-06-19T17:42:19.575288+00:00 app[web.1]: > npm run  serve
2020-06-19T17:42:19.575288+00:00 app[web.1]: 
2020-06-19T17:42:20.037740+00:00 app[web.1]: 
2020-06-19T17:42:20.037766+00:00 app[web.1]: > tr3@0.1.0 serve /app
2020-06-19T17:42:20.037767+00:00 app[web.1]: > vue-cli-service serve
2020-06-19T17:42:20.037767+00:00 app[web.1]: 
2020-06-19T17:42:20.045068+00:00 app[web.1]: sh: 1: vue-cli-service: not found
2020-06-19T17:42:20.049281+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-19T17:42:20.049568+00:00 app[web.1]: npm ERR! syscall spawn
2020-06-19T17:42:20.049812+00:00 app[web.1]: npm ERR! file sh
Run Code Online (Sandbox Code Playgroud)

这里也是我的 package.json

{
  "engines": {
    "node": "10.x"
  },
  "name": "tr3",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "start": "npm run  serve",
    "heroku-postinstall": "npm install && npm run build"
  },
  "heroku-postinstall": "npm install && npm run build",
  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^2.6.11",
    "vue-router": "^3.3.4",
     "vuex": "^3.4.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.4.0",
    "@vue/cli-plugin-eslint": "~4.4.0",
    "@vue/cli-service": "~4.4.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "vue-template-compiler": "^2.6.11"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}
Run Code Online (Sandbox Code Playgroud)

Jen*_*ses 8

几天前我遇到了同样的问题,我是 Vue.js 和 Heroku 的新手,但我能够找到帮助我解决问题的信息,我希望它可以帮助其他人。

在 package.json 的同级创建 static.json 文件:

{
    "root": "dist",
    "clean_urls": true,
    "routes": {
        "/**": "index.html"
    }
}
Run Code Online (Sandbox Code Playgroud)

将 static.json 文件添加到 git

git add static.json
git commit -m "add static configuration"
Run Code Online (Sandbox Code Playgroud)

部署到 Heroku

heroku buildpacks:add heroku/nodejs
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static
git push heroku master
Run Code Online (Sandbox Code Playgroud)

信息来源:部署| 命令行界面


cra*_*tad 7

我通过运行解决了这个问题:

heroku config:set NPM_CONFIG_PRODUCTION=false YARN_PRODUCTION=false

这篇Reddit 帖子Heroku 的 Skip 修剪说明对我很有帮助。结果我的小 vue 应用程序不需要访问devDependencies. 我不确定这是否是最合适的做法,但它解决了我的问题。