我在尝试部署名为tr3的应用程序时遇到问题(在localhost上运行良好,并且我还学会了使用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
但是链接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
这也是我的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"
]
}
答案 0 :(得分:6)
几天前,我遇到了同样的问题,我对Vue.js和Heroku还是陌生的,但是我能够找到此信息对我有所帮助,并希望对其他人有帮助。
在package.json的相同级别上创建static.json文件:
{
"root": "dist",
"clean_urls": true,
"routes": {
"/**": "index.html"
}
}
将static.json文件添加到git
git add static.json
git commit -m "add static configuration"
部署到Heroku
heroku buildpacks:add heroku/nodejs
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static
git push heroku master
信息来源:Deployment | Vue CLI
答案 1 :(得分:1)
我通过运行以下方法解决了这个问题:
devDependencies
此Reddit post和Heroku's Skip pruning说明对我有所帮助。原来我的Vue小应用程序不需要访问mod
的功能。我不确定这是否最合适,但这解决了我的问题。
答案 2 :(得分:1)
对于那些上述解决方案不起作用的人,你们可以尝试在你的 package.json 中的依赖项中添加“@vue/cli-service”依赖项。
解释:这是因为@vue/cli-service 仅在 devDependencies 上,所以当您在生产环境中部署您的应用程序时,您的项目中没有下载依赖项。