質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Q&A

解決済

1回答

602閲覧

herokuで「Internal Server Error」が出てしまう

退会済みユーザー

退会済みユーザー

総合スコア0

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

0グッド

0クリップ

投稿2022/08/06 11:04

前提

herokuにデプロイした環境では特定のページが「Internal Server Error」 になってしまっています。

実現したいこと

https://kaimemo1993.herokuapp.com/index
を動作するようにする

発生している問題・エラーメッセージ

2022-08-06T10:43:00.025495+00:00 app[web.1]: >> 24| <% items.forEach((item) => { %> 2022-08-06T10:43:00.025495+00:00 app[web.1]: 25| <li> 2022-08-06T10:43:00.025495+00:00 app[web.1]: 26| <div class="item-data"> 2022-08-06T10:43:00.025496+00:00 app[web.1]: 27| <span class="id-column"><%= item.id %></span> 2022-08-06T10:43:00.025496+00:00 app[web.1]: 2022-08-06T10:43:00.025496+00:00 app[web.1]: Cannot read properties of undefined (reading 'forEach') 2022-08-06T10:43:00.025497+00:00 app[web.1]: at eval ("/app/views/index.ejs":12:14) 2022-08-06T10:43:00.025497+00:00 app[web.1]: at index (/app/node_modules/ejs/lib/ejs.js:703:17) 2022-08-06T10:43:00.025497+00:00 app[web.1]: at tryHandleCache (/app/node_modules/ejs/lib/ejs.js:274:36) 2022-08-06T10:43:00.025498+00:00 app[web.1]: at View.exports.renderFile [as engine] (/app/node_modules/ejs/lib/ejs.js:491:10) 2022-08-06T10:43:00.025498+00:00 app[web.1]: at View.render (/app/node_modules/express/lib/view.js:135:8) 2022-08-06T10:43:00.025498+00:00 app[web.1]: at tryRender (/app/node_modules/express/lib/application.js:657:10) 2022-08-06T10:43:00.025498+00:00 app[web.1]: at Function.render (/app/node_modules/express/lib/application.js:609:3) 2022-08-06T10:43:00.025498+00:00 app[web.1]: at ServerResponse.render (/app/node_modules/express/lib/response.js:1039:7) 2022-08-06T10:43:00.025499+00:00 app[web.1]: at Query.<anonymous> (/app/app.js:23:11) 2022-08-06T10:43:00.025499+00:00 app[web.1]: at Query.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10) 2022-08-06T10:43:40.969754+00:00 heroku[router]: at=info method=GET path="/index" host=kaimemo1993.herokuapp.com request_id=7fdedf54-6374-4e8d-b56d-aaa8aec72d63 fwd="133.32.129.34" dyno=web.1 connect=0ms service=2ms status=500 bytes=404 protocol=https 2022-08-06T10:43:40.969848+00:00 app[web.1]: TypeError: /app/views/index.ejs:24 2022-08-06T10:43:40.969874+00:00 app[web.1]: 22| </div> 2022-08-06T10:43:40.969875+00:00 app[web.1]: 23| <ul class="table-body"> 2022-08-06T10:43:40.969877+00:00 app[web.1]: >> 24| <% items.forEach((item) => { %> 2022-08-06T10:43:40.969877+00:00 app[web.1]: 25| <li> 2022-08-06T10:43:40.969878+00:00 app[web.1]: 26| <div class="item-data"> 2022-08-06T10:43:40.969879+00:00 app[web.1]: 27| <span class="id-column"><%= item.id %></span> 2022-08-06T10:43:40.969880+00:00 app[web.1]: 2022-08-06T10:43:40.969880+00:00 app[web.1]: Cannot read properties of undefined (reading 'forEach') 2022-08-06T10:43:40.969880+00:00 app[web.1]: at eval ("/app/views/index.ejs":12:14) 2022-08-06T10:43:40.969881+00:00 app[web.1]: at index (/app/node_modules/ejs/lib/ejs.js:703:17) 2022-08-06T10:43:40.969881+00:00 app[web.1]: at tryHandleCache (/app/node_modules/ejs/lib/ejs.js:274:36) 2022-08-06T10:43:40.969882+00:00 app[web.1]: at View.exports.renderFile [as engine] (/app/node_modules/ejs/lib/ejs.js:491:10) 2022-08-06T10:43:40.969883+00:00 app[web.1]: at View.render (/app/node_modules/express/lib/view.js:135:8) 2022-08-06T10:43:40.969883+00:00 app[web.1]: at tryRender (/app/node_modules/express/lib/application.js:657:10) 2022-08-06T10:43:40.969884+00:00 app[web.1]: at Function.render (/app/node_modules/express/lib/application.js:609:3) 2022-08-06T10:43:40.969884+00:00 app[web.1]: at ServerResponse.render (/app/node_modules/express/lib/response.js:1039:7) 2022-08-06T10:43:40.969884+00:00 app[web.1]: at Query.<anonymous> (/app/app.js:23:11) 2022-08-06T10:43:40.969885+00:00 app[web.1]: at Query.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10) 2022-08-06T10:45:37.964389+00:00 app[web.1]: TypeError: /app/views/index.ejs:24 2022-08-06T10:45:37.964417+00:00 app[web.1]: 22| </div> 2022-08-06T10:45:37.964419+00:00 app[web.1]: 23| <ul class="table-body"> 2022-08-06T10:45:37.964419+00:00 app[web.1]: >> 24| <% items.forEach((item) => { %> 2022-08-06T10:45:37.964420+00:00 app[web.1]: 25| <li> 2022-08-06T10:45:37.964420+00:00 app[web.1]: 26| <div class="item-data"> 2022-08-06T10:45:37.964421+00:00 app[web.1]: 27| <span class="id-column"><%= item.id %></span> 2022-08-06T10:45:37.964422+00:00 app[web.1]: 2022-08-06T10:45:37.964422+00:00 app[web.1]: Cannot read properties of undefined (reading 'forEach') 2022-08-06T10:45:37.964422+00:00 app[web.1]: at eval ("/app/views/index.ejs":12:14) 2022-08-06T10:45:37.964423+00:00 app[web.1]: at index (/app/node_modules/ejs/lib/ejs.js:703:17) 2022-08-06T10:45:37.964423+00:00 app[web.1]: at tryHandleCache (/app/node_modules/ejs/lib/ejs.js:274:36) 2022-08-06T10:45:37.964424+00:00 app[web.1]: at View.exports.renderFile [as engine] (/app/node_modules/ejs/lib/ejs.js:491:10) 2022-08-06T10:45:37.964424+00:00 app[web.1]: at View.render (/app/node_modules/express/lib/view.js:135:8) 2022-08-06T10:45:37.964425+00:00 app[web.1]: at tryRender (/app/node_modules/express/lib/application.js:657:10) 2022-08-06T10:45:37.964425+00:00 app[web.1]: at Function.render (/app/node_modules/express/lib/application.js:609:3) 2022-08-06T10:45:37.964425+00:00 app[web.1]: at ServerResponse.render (/app/node_modules/express/lib/response.js:1039:7) 2022-08-06T10:45:37.964425+00:00 app[web.1]: at Query.<anonymous> (/app/app.js:23:11) 2022-08-06T10:45:37.964425+00:00 app[web.1]: at Query.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10)

該当のソースコード

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>かいめも!</title> <link rel="stylesheet" href="/css/style.css"> <script src="/send_url.js"></script> </head> <body> <header> <a href="/" class="header-logo">かいめも!</a> </header> <div class="container"> <div class="container-header"> <h1>買い物リスト</h1> <a href="/new" class="new-button">+ 新規登録</a> </div> <div class="index-table-wrapper"> <div class="table-head"> <span class="id-column">ID</span> <span>買うもの</span> </div> <ul class="table-body"> <% items.forEach((item) => { %> <li> <div class="item-data"> <span class="id-column"><%= item.id %></span> <span class="name-column"><%= item.name %></span> </div> <div class="item-menu"> <form action="/delete/<%=item.id%>" method="post"> <input type="submit" value="削除"> </form> <a href="/edit/<%=item.id%>">編集</a> </div> </li> <% }) %> </ul> </div> </div> </body> </html>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hoshi-takanori

2022/08/06 16:46

items が undefined ですね。そして、問題があるのは views/index.ejs じゃなくて、app.js の方かと…。
退会済みユーザー

退会済みユーザー

2022/08/07 05:30

ご指摘ありがとうございます! 以下、app.jsのソースコードになります… const express = require('express'); const mysql = require('mysql'); const app = express(); app.use(express.static('public')); app.use(express.urlencoded({extended: false})); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'pass', database: 'list_app' }); app.get('/', (req, res) => { res.render('top.ejs'); }); app.get('/index', (req, res) => { connection.query( 'SELECT * FROM items', (error, results) => { res.render('index.ejs', {items: results}); } ); }); app.get('/new', (req, res) => { res.render('new.ejs'); }); app.post('/create', (req, res) => { connection.query( 'INSERT INTO items (name) VALUES (?)', [req.body.itemName], (error, results) => { res.redirect('/index'); } ); }); app.post('/delete/:id', (req, res) => { connection.query( 'DELETE FROM items WHERE id = ?', [req.params.id], (error,results) => { res.redirect('/index'); } ); }); app.get('/edit/:id', (req, res) => { connection.query( 'SELECT * FROM items WHERE id = ?', [req.params.id], (error, results) => { res.render('edit.ejs',{item:results[0]}); } ); }); app.post('/update/:id', (req, res) => { connection.query( 'UPDATE items SET name = ? WHERE id = ?', [req.body.itemName , req.params.id], (error, results) => { res.redirect('/index'); } ); }); const PORT=process.env.PORT || 3000; app.listen(PORT,()=>{ console.log("listening server") })
hoshi-takanori

2022/08/07 06:29

app.get('/index', 〜 のところで、SQL のエラーを無視してますね。データベースは何をお使いですか?
退会済みユーザー

退会済みユーザー

2022/08/07 07:30

データベースはmysqlですがherokuの方でClearDBというものも作ってあります
退会済みユーザー

退会済みユーザー

2022/08/07 10:56

教えてくださったURLの通りに試し、その後試行錯誤したのですが、このようなログのエラーが出てしまいました… 2022-08-07T10:40:54.660309+00:00 app[web.1]: fatal: true, 2022-08-07T10:40:54.660309+00:00 app[web.1]: code: 'PROTOCOL_CONNECTION_LOST' 2022-08-07T10:40:54.660309+00:00 app[web.1]: } 2022-08-07T10:40:54.787439+00:00 heroku[web.1]: Process exited with status 1 2022-08-07T10:40:55.165555+00:00 heroku[web.1]: State changed from up to crashed 2022-08-07T10:42:00.000000+00:00 app[api]: Build started by user akiress55555@gmail.com 2022-08-07T10:42:15.000000+00:00 app[api]: Build succeeded 2022-08-07T10:42:15.563893+00:00 app[api]: Release v23 created by user akiress55555@gmail.com 2022-08-07T10:42:15.563893+00:00 app[api]: Deploy 5d9b589b by user akiress55555@gmail.com 2022-08-07T10:42:15.940822+00:00 heroku[web.1]: State changed from crashed to starting 2022-08-07T10:42:17.653572+00:00 heroku[web.1]: Starting process with command `npm start` 2022-08-07T10:42:18.954655+00:00 app[web.1]: 2022-08-07T10:42:18.954673+00:00 app[web.1]: > list-app@1.0.0 start 2022-08-07T10:42:18.954674+00:00 app[web.1]: > node app.js 2022-08-07T10:42:18.954674+00:00 app[web.1]: 2022-08-07T10:42:19.152993+00:00 app[web.1]: /app/app.js:98 2022-08-07T10:42:19.152995+00:00 app[web.1]: app.listen(pricess.env.PORT || 3000); 2022-08-07T10:42:19.152995+00:00 app[web.1]: ^ 2022-08-07T10:42:19.152996+00:00 app[web.1]: 2022-08-07T10:42:19.152996+00:00 app[web.1]: ReferenceError: pricess is not defined 2022-08-07T10:42:19.152996+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:98:12) 2022-08-07T10:42:19.153010+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14) 2022-08-07T10:42:19.153010+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) 2022-08-07T10:42:19.153011+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32) 2022-08-07T10:42:19.153012+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12) 2022-08-07T10:42:19.153015+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) 2022-08-07T10:42:19.153016+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 2022-08-07T10:42:19.276759+00:00 heroku[web.1]: Process exited with status 1 2022-08-07T10:42:19.968221+00:00 heroku[web.1]: State changed from starting to crashed 2022-08-07T10:42:21.325906+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=kaimemo1993.herokuapp.com request_id=0866c8ca-9dce-4415-9c0b-64a84af95a6e fwd="133.32.129.34" dyno= connect= service= status=503 bytes= protocol=https 2022-08-07T10:43:51.000000+00:00 app[api]: Build started by user akiress55555@gmail.com 2022-08-07T10:44:06.000000+00:00 app[api]: Build succeeded 2022-08-07T10:44:06.191933+00:00 app[api]: Release v24 created by user akiress55555@gmail.com 2022-08-07T10:44:06.191933+00:00 app[api]: Deploy db996d33 by user akiress55555@gmail.com 2022-08-07T10:44:07.717519+00:00 heroku[web.1]: State changed from crashed to starting 2022-08-07T10:44:09.416758+00:00 heroku[web.1]: Starting process with command `npm start` 2022-08-07T10:44:11.161983+00:00 app[web.1]: 2022-08-07T10:44:11.161998+00:00 app[web.1]: > list-app@1.0.0 start 2022-08-07T10:44:11.161998+00:00 app[web.1]: > node app.js 2022-08-07T10:44:11.161998+00:00 app[web.1]: 2022-08-07T10:44:11.324000+00:00 app[web.1]: /app/app.js:92 2022-08-07T10:44:11.324002+00:00 app[web.1]: app.listen(pricess.env.PORT || 3000); 2022-08-07T10:44:11.324002+00:00 app[web.1]: ^ 2022-08-07T10:44:11.324003+00:00 app[web.1]: 2022-08-07T10:44:11.324003+00:00 app[web.1]: ReferenceError: pricess is not defined 2022-08-07T10:44:11.324003+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:92:12) 2022-08-07T10:44:11.324004+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14) 2022-08-07T10:44:11.324004+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) 2022-08-07T10:44:11.324004+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32) 2022-08-07T10:44:11.324005+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12) 2022-08-07T10:44:11.324005+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) 2022-08-07T10:44:11.324005+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 2022-08-07T10:44:11.461688+00:00 heroku[web.1]: Process exited with status 1 2022-08-07T10:44:11.602233+00:00 heroku[web.1]: State changed from starting to crashed 2022-08-07T10:44:11.609249+00:00 heroku[web.1]: State changed from crashed to starting 2022-08-07T10:44:13.599801+00:00 heroku[web.1]: Starting process with command `npm start` 2022-08-07T10:44:14.966460+00:00 app[web.1]: 2022-08-07T10:44:14.974097+00:00 app[web.1]: > list-app@1.0.0 start 2022-08-07T10:44:14.974110+00:00 app[web.1]: > node app.js 2022-08-07T10:44:14.974110+00:00 app[web.1]: 2022-08-07T10:44:15.169246+00:00 app[web.1]: /app/app.js:92 2022-08-07T10:44:15.169259+00:00 app[web.1]: app.listen(pricess.env.PORT || 3000); 2022-08-07T10:44:15.169259+00:00 app[web.1]: ^ 2022-08-07T10:44:15.169259+00:00 app[web.1]: 2022-08-07T10:44:15.169260+00:00 app[web.1]: ReferenceError: pricess is not defined 2022-08-07T10:44:15.169260+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:92:12) 2022-08-07T10:44:15.169263+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14) 2022-08-07T10:44:15.169264+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) 2022-08-07T10:44:15.169267+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32) 2022-08-07T10:44:15.169267+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12) 2022-08-07T10:44:15.169270+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) 2022-08-07T10:44:15.169270+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 2022-08-07T10:44:15.325765+00:00 heroku[web.1]: Process exited with status 1 2022-08-07T10:44:15.383356+00:00 heroku[web.1]: State changed from starting to crashed 2022-08-07T10:44:36.602733+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=kaimemo1993.herokuapp.com request_id=6a83e025-ccaf-4c1a-9e62-308c4b9d9699 fwd="133.32.129.34" dyno= connect= service= status=503 bytes= protocol=https 2022-08-07T10:51:52.000000+00:00 app[api]: Build started by user akiress55555@gmail.com 2022-08-07T10:52:06.658033+00:00 app[api]: Deploy cb1afda6 by user akiress55555@gmail.com 2022-08-07T10:52:06.658033+00:00 app[api]: Release v25 created by user akiress55555@gmail.com 2022-08-07T10:52:06.945288+00:00 heroku[web.1]: State changed from crashed to starting 2022-08-07T10:52:07.000000+00:00 app[api]: Build succeeded 2022-08-07T10:52:08.668441+00:00 heroku[web.1]: Starting process with command `npm start` 2022-08-07T10:52:09.913348+00:00 app[web.1]: 2022-08-07T10:52:09.913364+00:00 app[web.1]: > list-app@1.0.0 start 2022-08-07T10:52:09.913364+00:00 app[web.1]: > node app.js 2022-08-07T10:52:09.913364+00:00 app[web.1]: 2022-08-07T10:52:10.116507+00:00 app[web.1]: /app/app.js:72 2022-08-07T10:52:10.116509+00:00 app[web.1]: app.listen(pricess.env.PORT || 3000); 2022-08-07T10:52:10.116510+00:00 app[web.1]: ^ 2022-08-07T10:52:10.116510+00:00 app[web.1]: 2022-08-07T10:52:10.116510+00:00 app[web.1]: ReferenceError: pricess is not defined 2022-08-07T10:52:10.116510+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:72:12) 2022-08-07T10:52:10.116511+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14) 2022-08-07T10:52:10.116511+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) 2022-08-07T10:52:10.116511+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32) 2022-08-07T10:52:10.116512+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12) 2022-08-07T10:52:10.116513+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) 2022-08-07T10:52:10.116513+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 2022-08-07T10:52:10.239239+00:00 heroku[web.1]: Process exited with status 1 2022-08-07T10:52:10.578661+00:00 heroku[web.1]: State changed from starting to crashed 2022-08-07T10:53:33.207218+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=kaimemo1993.herokuapp.com request_id=f2b8fc36-d506-48cc-9715-3b54e3629d6a fwd="133.32.129.34" dyno= connect= service= status=503 bytes= protocol=https
hoshi-takanori

2022/08/07 19:40

> app.listen(pricess.env.PORT || 3000); pricess じゃなくて process かな。
退会済みユーザー

退会済みユーザー

2022/08/08 05:10

できました! 本当にありがとうございました!!
guest

回答1

0

ベストアンサー

追記・修正依頼欄参照。

投稿2022/08/09 08:39

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問