在Heroku上部署时遇到麻烦 [英] Got troubles to deploy on Heroku

查看:81
本文介绍了在Heroku上部署时遇到麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署在Heroku上创建的项目,但是这样做有些麻烦...

I'm trying to deploy a project I created on Heroku and I have some trouble to do it...

我无法弄清楚我的部署有什么问题,希望大家能为我提供帮助:)

I can't figure out what's wrong with my deployment I hope guys you could help me :)

我认为这是一个不确定的问题...

I think it's a path issue not sure ...

remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  10.11.0
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 10.11.0...
remote:        Downloading and installing node 10.11.0...
remote:        Using default npm version: 6.4.1
remote:
remote: -----> Building dependencies
remote:        Installing node modules (package.json + package-lock)
remote:
remote:        > nodemon@1.18.4 postinstall /tmp/build_9767eb39664bb3efb05f0e963d14a2f1/node_modules/nodemon
remote:        > node bin/postinstall || exit 0
remote:
remote:        Love nodemon? You can now support the project via the open collective:
remote:         > https://opencollective.com/nodemon/donate
remote:
remote:        added 319 packages from 191 contributors and audited 2482 packages in 7.784s
remote:        found 0 vulnerabilities
remote:
remote:        Running heroku-postbuild
remote:
remote:        > server@1.0.0 heroku-postbuild /tmp/build_9767eb39664bb3efb05f0e963d14a2f1
remote:        > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote:        up to date in 0.76s
remote:        found 0 vulnerabilities
remote:
remote: npm ERR! path /tmp/build_9767eb39664bb3efb05f0e963d14a2f1/client/package.json
remote: npm ERR! code ENOENT
remote: npm ERR! errno -2
remote: npm ERR! syscall open
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_9767eb39664bb3efb05f0e963d14a2f1/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.vWMnG/_logs/2018-11-07T16_38_24_492Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! server@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 server@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.vWMnG/_logs/2018-11-07T16_38_24_505Z-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:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
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 agile-badlands-25978.
remote:
To https://git.heroku.com/agile-badlands-25978.git
 ! [remote rejected] master -> master (pre-receive hook declined)

我的项目:

PROJETNAME
- client
    --- node_modules
    --- public
    --- src
    --- package.lock.json
    --- package.json
    --- .gitignore
- node_modules
- config
- models
- routes
- validation
- .gitignore
- package.lock.json
- package.json
- server.js

server.js

server.js

const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');
const path = require('path');

// Routes
const users = require('./routes/api/users');
const shops = require('./routes/api/shops');
const profile = require('./routes/api/profile');
const mail = require('./routes/contact/mail');

const app = express();

// Body parser middleware
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());

// DB Config
const db = require('./config/keys').mongoURI;

// Connect to MongoDB
mongoose
    .connect(db)
    .then(() => console.log('MongoDB Connected'))
    .catch(err => console.log(err))


// Passport Middleware
app.use(passport.initialize());

// Passport Config
require('./config/passport')(passport);

// Use Routes
app.use('/api/users', users);
app.use('/api/shops', shops);
app.use('/api/profile', profile);
app.use('/contact/mail', mail);

// Server static assets if in production
if (process.env.NODE_ENV === 'production') {
    // Set static folder
    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 running on ${port}`));

server => package.json

server => package.json

{
  "name": "server",
  "version": "1.0.0",
  "engines": {
    "node": "10.11.0"
  },
  "description": "",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "dev": "nodemon server.js",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "express": "^4.16.4",
    "jsonwebtoken": "^8.3.0",
    "mongoose": "^5.3.5",
    "nodemailer": "^4.6.8",
    "nodemon": "^1.18.4",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "validator": "^10.8.0"
  },
  "devDependencies": {},
  "author": "Cyril G",
  "license": "ISC"
}

推荐答案

由于客户端目录中的.git文件夹,实际上出现了此问题.从客户端删除该.git目录并运行

This problem is actually occurred due to .git folder in client directory. Delete that .git directory from client side and run

git rm -f --cached client && git add . && git commit -m 'Add client folder back to git repo' && git push heroku master

这里解决了: https://github.com/bradtraversy/mern_shopping_list/issues/7

这篇关于在Heroku上部署时遇到麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆