DEV Community

Discussion on: Build a simple app using Node JS and MySQL.

Collapse
 
lexandra987 profile image
lexandra987

Hi, I have a problem:

TypeError: C:\players\node-mysql-crud-app\views\index.ejs:18
16|

17|                 <tbody>

18| <% players.forEach((player) => { %>

19|                         <tr>

20|                             <th scope="row"><%= player.id %></th>

21|                             <td><img src="/assets/img/<%= player.image %>" class="rounded-circle player-img" alt=""></td>

players.forEach is not a function
at eval (eval at compile (C:\players\node-mysql-crud-app\node_modules\ejs\lib\ejs.js:618:12), :28:16)
at returnedFn (C:\players\node-mysql-crud-app\node_modules\ejs\lib\ejs.js:653:17)
at tryHandleCache (C:\players\node-mysql-crud-app\node_modules\ejs\lib\ejs.js:251:36)
at View.exports.renderFile as engine
at View.render (C:\players\node-mysql-crud-app\node_modules\express\lib\view.js:135:8)
at tryRender (C:\players\node-mysql-crud-app\node_modules\express\lib\application.js:640:10)
at Function.render (C:\players\node-mysql-crud-app\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (C:\players\node-mysql-crud-app\node_modules\express\lib\response.js:1016:7)
at Query.db.query (C:\players\node-mysql-crud-app\routes\index.js:10:17)
at Query. (C:\players\node-mysql-crud-app\node_modules\mysql\lib\Connection.js:525:10)

How can I fix it?

BR,
Aleksandra

Collapse
 
edensharvit profile image
EDEN SHARVIT

Can u tell us how did u manage to fix your issue?
I'm also stuck with the same error....

Collapse
 
lexandra987 profile image
lexandra987

but ok, it was no question. it was just a stupid error in my index.ejs file. Now it works! :)

Collapse
 
coolnin profile image
coolnin

I am getting the same problem what u did?

Thread Thread
 
udayparekh2006 profile image
Uday Parekh

Have you got a solution?

Thread Thread
 
dikshabhattacharjee profile image
dikshabhattacharjee

Any solution?

Collapse
 
dikshabhattacharjee profile image
dikshabhattacharjee

How did you fix it.please help..

Collapse
 
rafad900 profile image
rafad900

One of the things that you can check is in inside /routes/index.js
Make sure that the players: result is not in any quotes.
foreach is a function of arrays. If you have 'result', that is a string.

Collapse
 
albertgabiro profile image
Gabiro Albert • Edited

hy i have same question online 18

how did you fix it
please help