Y S*_*ITH 5 git heroku node.js npm mern
我曾尝试在 Heroku 上部署 MERN 堆栈应用程序。我遵循了heroku文档中给出的过程。但是,不知怎的,我无法将应用程序部署到heroku。
以下是我的 server.js 代码:
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const path = require('path');
const items = require('./routes/api/items');
const app = express();
app.use(bodyParser.json());
const db = require('./config/keys').mongoURI;
mongoose
.connect(db)
.then(() => console.log('MongoDB Connected...'))
.catch(err => console.log(err));
app.use('/api/items', items);
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server started on port ${port}`));
Run Code Online (Sandbox Code Playgroud)
以下是我在服务器文件夹中的 package.json 文件:
{
"name": "mern_shopping_list",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"client-install" : "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev" : "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --
prefix client"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"concurrently": "^5.1.0",
"express": "^4.17.1",
"mongoose": "^5.9.0"
},
"devDependencies": {
"nodemon": "^2.0.2"
}
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误如下:
remote: -----> Build
remote: Running heroku-postbuild
remote:
remote: > mern_shopping_list@1.0.0 heroku-postbuild
/tmp/build_6dafb80a10b85bd553ee344141227145
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix
client
remote:
remote: up to date in 0.284s
remote: found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_6dafb80a10b85bd553ee344141227145/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open
'/tmp/build_6dafb80a10b85bd553ee344141227145/client/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
remote: npm ERR! enoent
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.2Rtdv/_logs/2020-02-15T15_35_57_654Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! mern_shopping_list@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install
--prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 254
remote: npm ERR!
remote: npm ERR! Failed at the mern_shopping_list@1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output
above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.2Rtdv/_logs/2020-02-15T15_35_57_666Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: Some possible problems:
remote:
remote: - node_modules checked into source control
remote: https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
remote:
remote: - Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to damp-anchorage-46764.
remote:
To https://git.heroku.com/damp-anchorage-46764.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/damp-anchorage-46764.git'
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一些在线链接,但没有一个给出所需的结果。有人能建议我如何解决这个问题吗?
小智 7
cd 到 /client 删除 .git 文件夹
rm -rf .git
Run Code Online (Sandbox Code Playgroud)
还可以通过以下命令重置 git:
git rm --cached . -rf
Run Code Online (Sandbox Code Playgroud)
正如米娜·阿米尔(Mina Amir)提到的那样,您的更改已经由客户端目录中的 git 跟踪,并且不会在提交中使用服务器/主 git 再次跟踪
小智 0
尝试从 /client 中删除 .git 文件夹,因为根目录中的主 .git 文件夹看不到 /client/package.json 并且不跟踪 /client 内的任何更改。之后从头开始将所有内容提交到根文件夹中
| 归档时间: |
|
| 查看次数: |
2748 次 |
| 最近记录: |