我已经创建了一个在我的本地服务器上正常运行的Web应用程序(Vue JS前端,Sails JS后端)。但是,当我尝试运行它时,我会遇到错误;主要是依赖错误。我已经在Heroku上部署了它。我必须在我的app文件夹的根目录中创建一个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 [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~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 [email protected]~start: CWD: /media/adesuwa/Files/Programming/Dev test/zigy-demo-store
10 silly lifecycle [email protected]~start: Args: [ '-c',
10 silly lifecycle 'cd backend && npm i && npm run dev & cd frontend && npm i && npm start' ]
11 silly lifecycle [email protected]~start: Returned: code: 1 signal: null
12 info lifecycle [email protected]~start: Failed to exec start script
13 verbose stack Error: [email protected] 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 [email protected]
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 [email protected] start: `cd backend && npm i && npm run dev & cd frontend && npm i && npm start`
22 error Exit status 1
23 error Failed at the [email protected] start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
看起来我的路径有问题。在错误日志中,我看到链式命令是:
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
好的,我只是将前端和后端部署为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。