我有一个Node.js应用程序在我的本地计算机上运行,但是当我将其发送到Heroku时,它崩溃了。错误日志给出错误fs-extra
和H10错误,并显示:
2019-07-27T10:26:04.960769+00:00 app[web.1]: at Object.<anonymous> (/app/src/app.js:45:9)
2019-07-27T10:26:04.960771+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:776:30)
2019-07-27T10:26:04.960774+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
2019-07-27T10:26:04.960776+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-07-27T10:26:04.977073+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-07-27T10:26:04.977532+00:00 app[web.1]: npm ERR! errno 1
2019-07-27T10:26:04.978645+00:00 app[web.1]: npm ERR! photo_gallery@1.0.0 start: `node src/index.js`
2019-07-27T10:26:04.978819+00:00 app[web.1]: npm ERR! Exit status 1
2019-07-27T10:26:04.979094+00:00 app[web.1]: npm ERR!
2019-07-27T10:26:04.979279+00:00 app[web.1]: npm ERR! Failed at the photo_gallery@1.0.0 start script.
2019-07-27T10:26:04.979480+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-07-27T10:26:04.987401+00:00 app[web.1]:
2019-07-27T10:26:04.987599+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-07-27T10:26:04.987740+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-07-27T10_26_04_980Z-debug.log
2019-07-27T10:26:05.073078+00:00 heroku[web.1]: State changed from starting to crashed
2019-07-27T10:26:05.050705+00:00 heroku[web.1]: Process exited with status 1
2019-07-27T16:02:15.908996+00:00 heroku[web.1]: State changed from crashed to starting
2019-07-27T16:02:18.219026+00:00 heroku[web.1]: Starting process with command `npm start`
2019-07-27T16:02:20.146271+00:00 app[web.1]:
2019-07-27T16:02:20.146290+00:00 app[web.1]: > photo_gallery@1.0.0 start /app
2019-07-27T16:02:20.146293+00:00 app[web.1]: > node src/index.js
2019-07-27T16:02:20.146295+00:00 app[web.1]:
2019-07-27T16:02:20.963437+00:00 app[web.1]: mongodb+srv://pablofonseca:mongoDeveloper3294MD@cluster0-6auoq.mongodb.net/test?retryWrites=true&w=majority
2019-07-27T16:02:20.963482+00:00 app[web.1]:
2019-07-27T16:02:21.136238+00:00 app[web.1]: internal/modules/cjs/loader.js:638
2019-07-27T16:02:21.136242+00:00 app[web.1]: throw err;
2019-07-27T16:02:21.136244+00:00 app[web.1]: ^
2019-07-27T16:02:21.136246+00:00 app[web.1]:
2019-07-27T16:02:21.136248+00:00 app[web.1]: Error: Cannot find module 'fs-extra'
2019-07-27T16:02:21.136250+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
2019-07-27T16:02:21.136252+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:562:25)
2019-07-27T16:02:21.136254+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:690:17)
2019-07-27T16:02:21.136256+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-07-27T16:02:21.136258+00:00 app[web.1]: at Object.<anonymous> (/app/src/routes/index.js:13:12)
2019-07-27T16:02:21.136260+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:776:30)
2019-07-27T16:02:21.136262+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
2019-07-27T16:02:21.136264+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-07-27T16:02:21.136266+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-07-27T16:02:21.136268+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-07-27T16:02:21.136270+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:690:17)
2019-07-27T16:02:21.136272+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-07-27T16:02:21.136274+00:00 app[web.1]: at Object.<anonymous> (/app/src/app.js:45:9)
2019-07-27T16:02:21.136276+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:776:30)
2019-07-27T16:02:21.136278+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
2019-07-27T16:02:21.136280+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-07-27T16:02:21.147675+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-07-27T16:02:21.148310+00:00 app[web.1]: npm ERR! errno 1
2019-07-27T16:02:21.149706+00:00 app[web.1]: npm ERR! photo_gallery@1.0.0 start: `node src/index.js`
2019-07-27T16:02:21.149893+00:00 app[web.1]: npm ERR! Exit status 1
2019-07-27T16:02:21.150233+00:00 app[web.1]: npm ERR!
2019-07-27T16:02:21.150467+00:00 app[web.1]: npm ERR! Failed at the photo_gallery@1.0.0 start script.
2019-07-27T16:02:21.150692+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-07-27T16:02:21.156522+00:00 app[web.1]:
2019-07-27T16:02:21.156731+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-07-27T16:02:21.156803+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-07-27T16_02_21_152Z-debug.log
2019-07-27T16:02:21.228062+00:00 heroku[web.1]: State changed from starting to crashed
2019-07-27T16:02:21.207666+00:00 heroku[web.1]: Process exited with status 1
2019-07-27T21:54:23.980325+00:00 heroku[web.1]: State changed from crashed to starting
2019-07-27T21:54:26.162423+00:00 heroku[web.1]: Starting process with command `npm start`
2019-07-27T21:54:28.335412+00:00 app[web.1]:
2019-07-27T21:54:28.335428+00:00 app[web.1]: > photo_gallery@1.0.0 start /app
2019-07-27T21:54:28.335430+00:00 app[web.1]: > node src/index.js
2019-07-27T21:54:28.335431+00:00 app[web.1]:
2019-07-27T21:54:28.934757+00:00 app[web.1]: mongodb+srv://pablofonseca:mongoDeveloper3294MD@cluster0-6auoq.mongodb.net/test?retryWrites=true&w=majority
2019-07-27T21:54:28.934788+00:00 app[web.1]:
2019-07-27T21:54:29.069816+00:00 app[web.1]: internal/modules/cjs/loader.js:638
2019-07-27T21:54:29.069819+00:00 app[web.1]: throw err;
2019-07-27T21:54:29.069821+00:00 app[web.1]: ^
2019-07-27T21:54:29.069822+00:00 app[web.1]:
2019-07-27T21:54:29.069824+00:00 app[web.1]: Error: Cannot find module 'fs-extra'
2019-07-27T21:54:29.069827+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
2019-07-27T21:54:29.069829+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:562:25)
2019-07-27T21:54:29.069831+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:690:17)
2019-07-27T21:54:29.069833+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-07-27T21:54:29.069834+00:00 app[web.1]: at Object.<anonymous> (/app/src/routes/index.js:13:12)
2019-07-27T21:54:29.069836+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:776:30)
2019-07-27T21:54:29.069837+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
2019-07-27T21:54:29.069839+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-07-27T21:54:29.069840+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-07-27T21:54:29.069842+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-07-27T21:54:29.069843+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:690:17)
2019-07-27T21:54:29.069845+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-07-27T21:54:29.069847+00:00 app[web.1]: at Object.<anonymous> (/app/src/app.js:45:9)
2019-07-27T21:54:29.069848+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:776:30)
2019-07-27T21:54:29.069850+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
2019-07-27T21:54:29.069851+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-07-27T21:54:29.078039+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-07-27T21:54:29.078417+00:00 app[web.1]: npm ERR! errno 1
2019-07-27T21:54:29.079496+00:00 app[web.1]: npm ERR! photo_gallery@1.0.0 start: `node src/index.js`
2019-07-27T21:54:29.079602+00:00 app[web.1]: npm ERR! Exit status 1
2019-07-27T21:54:29.079795+00:00 app[web.1]: npm ERR!
2019-07-27T21:54:29.079911+00:00 app[web.1]: npm ERR! Failed at the photo_gallery@1.0.0 start script.
2019-07-27T21:54:29.080018+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-07-27T21:54:29.084860+00:00 app[web.1]:
2019-07-27T21:54:29.085002+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-07-27T21:54:29.085091+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-07-27T21_54_29_081Z-debug.log
2019-07-27T21:54:29.152385+00:00 heroku[web.1]: State changed from starting to crashed
2019-07-27T21:54:29.134549+00:00 heroku[web.1]: Process exited with status 1
2019-07-28T01:26:30.759278+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=crgrupodediseno.herokuapp.com request_id=d37398a6-a39e-4165-bb4f-407f45eb695b fwd="201.192.136.17" dyno= connect= service= status=503 bytes= protocol=https
2019-07-28T01:26:31.316040+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=crgrupodediseno.herokuapp.com request_id=50cdca96-9a21-4382-997b-3b2f81f5564e fwd="201.192.136.17" dyno= connect= service= status=503 bytes= protocol=https
这是我使用“ heroku logs --tail”命令收到的记录。 以前有没有人知道过,可能是什么原因引起的?我找不到解决方法。
实际上我的计算机上安装了fs-extra
模块,并且该应用程序在本地正常运行,但是在Heroku中无法正常工作。
在这里,我附加了index.js文件的代码,以便您了解我的设置方式:
const { Router } = require('express');
const router = Router();
const Photo = require('../modules/Photo');
const cloudinary = require('cloudinary');
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET
});
const fs = require('fs-extra');
router.get('/', async(req, res) => {
const photos = await Photo.find(); //Nos trae todas las fotos almacenadas en MongoDB.
console.log(photos);
res.render('images', { photos });
});
router.get('/images/add', async(req, res) => {
const photos = await Photo.find(); //Nos trae todas las fotos almacenadas en MongoDB.
res.render('image_form', { photos });
});
router.post('/images/add', async(req, res) => {
console.log(req.body); //Informacion de la imagen
const { title, description } = req.body;
console.log(req.file); //Imagen
const result = await cloudinary.v2.uploader.upload(req.file.path);
console.log(result);
const newPhoto = new Photo({
title: title,
description: description,
imageURL: result.url,
public_id: result.public_id
});
await newPhoto.save();
await fs.unlink(req.file.path);
res.redirect('/images/add');
});
router.get('/images/delete/:photo_id', async(req, res) => {
const { photo_id } = req.params;
const photo = await Photo.findByIdAndDelete(photo_id); //Eliminar la información de la base de datos.
const result = await cloudinary.v2.uploader.destroy(photo.public_id); //Eliminar la información subida a Cloudinary.
console.log(result);
res.redirect('/images/add');
});
module.exports = router;
答案 0 :(得分:0)
实际上我的计算机上安装了
fs-extra
模块
这无关紧要。您计算机上安装的模块对Heroku会有什么影响?
必须在package.json
和package-lock.json
或yarn.lock
中定义所有依赖项。
fs-extra
添加package.json
和任何其他依赖项,npm install
或yarn
,package.json
并锁定文件,在构建过程中,Heroku将安装这些文件中列出的依赖项。
这也可能是一个问题:
PORT = 4000
,但是由于您尚未共享server.js
,因此很难确定。 Heroku populates the PORT
environment variable,这是服务器必须绑定到的端口。