我的vue.js + Sails.js应用程序无法在Heroku上运行

时间:2019-02-12 16:37:30

标签: heroku vue.js sails.js

我创建了一个网络应用程序(Vue JS前端,Sails JS后端),该应用程序可以在本地服务器上正常运行。但是,当我尝试运行它时,会出现错误。主要是依赖错误。我已经在Heroku上部署了它。我必须在我的应用文件夹的根目录中创建一个package.json文件。

这是应用程序树的样子:

root folder
    |---frontend
        |---package.json file
    |---backend
        |---package.json file
    |---package.json file

我使用vue cli webpack创建了前端应用程序。

"name": "zigy-demo-store",
"version": "1.0.0",
"description": "A demo online store with Admin functions.",
"main": "backend/app.js",
"scripts": {
     "dev": "cd backend && npm i && npm run dev & cd frontend && npm i && npm run build",
     "start": "cd backend && npm i && npm run dev & cd frontend && npm i && npm start"
},
"dependencies": {
    "sails": ""
},
"repository": {
    "type": "git",
},
"engines": {
  "node": "^10.15",
  "npm": "6.7.0"
}
}

有些错误

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/home/adesuwa/.npm-global/bin/npm', 'start' ]
2 info using npm@6.7.0
3 info using node@v10.15.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle zigy-demo-store@1.0.0~prestart: zigy-demo-store@1.0.0
6 info lifecycle zigy-demo-store@1.0.0~start: zigy-demo-store@1.0.0
7 verbose lifecycle zigy-demo-store@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle zigy-demo-store@1.0.0~start: PATH: /home/adesuwa/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/media/adesuwa/Files/Programming/Dev test/zigy-demo-store/node_modules/.bin:/home/adesuwa/dart-sass/:/home/adesuwa/.npm-global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle zigy-demo-store@1.0.0~start: CWD: /media/adesuwa/Files/Programming/Dev test/zigy-demo-store
10 silly lifecycle zigy-demo-store@1.0.0~start: Args: [ '-c',
10 silly lifecycle   'cd backend && npm i && npm run dev & cd frontend && npm i && npm start' ]
11 silly lifecycle zigy-demo-store@1.0.0~start: Returned: code: 1  signal: null
12 info lifecycle zigy-demo-store@1.0.0~start: Failed to exec start script
13 verbose stack Error: zigy-demo-store@1.0.0 start: `cd backend && npm i && npm run dev & cd frontend && npm i && npm start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/home/adesuwa/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/home/adesuwa/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid zigy-demo-store@1.0.0
15 verbose cwd /media/adesuwa/Files/Programming/Dev test/zigy-demo-store
16 verbose Linux 4.15.0-45-generic
17 verbose argv "/usr/bin/node" "/home/adesuwa/.npm-global/bin/npm" "start"
18 verbose node v10.15.0
19 verbose npm  v6.7.0
20 error code ELIFECYCLE
21 error errno 1
22 error zigy-demo-store@1.0.0 start: `cd backend && npm i && npm run dev & cd frontend && npm i && npm start`
22 error Exit status 1
23 error Failed at the zigy-demo-store@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

2 个答案:

答案 0 :(得分:0)

我认为您的路径有问题。在错误日志中,我看到链接的命令是:

cd backend && npm i && npm run dev & cd frontend && npm i && npm start

根据您的树结构,frontend目录中没有backend目录,这会使cd frontend失败。在进入../之前,尝试在其中添加frontend到一个级别:

cd backend && npm i && npm run dev & cd ../frontend && npm i && npm start

答案 1 :(得分:0)

好,所以我只是将前端和后端作为单独的应用程序部署在Heroku上。我按照本教程在Heroku上进行了Vue.js + Webpack的部署:https://codeburst.io/quick-n-clean-way-to-deploy-vue-webpack-apps-on-heroku-b522d3904bc8

虽然我没有推送前端文件夹,但只推送了位于前端文件夹中的dist /文件夹。除了git init部分外,我按照本文的步骤操作。我进入dist文件夹,然后在其中进行git init。