vag*_*vaf 5 ejs node.js express parceljs
I am trying to parcel my nodejs app which uses epxress and ejs but I am getting a parcel error during the process
My app already runs as expected if I use the standard way:
node app.js
However, when I try to run it with parcel I am getting an error.
my package.json (showing only relevant parts):
"scripts": {
"start": "parcel views/index.ejs",
"build": "parcel build --public-url . views/index.ejs"
},
"dependencies": {
"parcel-plugin-ejs": "^0.2.0",
"parcel-plugin-ejs-template": "^0.1.1",
},
"devDependencies": {
"parcel-bundler": "^1.12.3"
}
Run Code Online (Sandbox Code Playgroud)
this is how I am rendering the page:
router.get("/" , function(req, res) {
(async () => {
const client = await pool.connect()
try {
const result = await client.query('select id, name from mytable')
res.render("index", {
items: result.rows
})
} finally {
client.release()
}
})().catch(e => console.error(e.stack))
});
Run Code Online (Sandbox Code Playgroud)
and my index.ejs file:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My website</title>
</head>
<body>
<div class="menu">
<% items.forEach(function(row){ %>
<div class="item" data-value="<%= row.id %>"> <%= row.name %></div>
<% }) %>
</div>
.
.
.
.
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
I would expect my app to be be parceled successfully and to be able to access it through the url provided.
However, I am getting this error:
$ npm run start
> my_project@1.0.0 start /home/user/my_project
> parcel views/index.ejs
Server running at http://localhost:1234
/home/user/my_project/views/index.ejs: items is not defined
at eval (eval at compile (/home/user/my_project/node_modules/ejs/lib/ejs.js:618:12), <anonymous>:5:8)
at returnedFn (/home/user/my_project/node_modules/ejs/lib/ejs.js:653:17)
at EjsAsset.generate (/home/user/my_project/node_modules/parcel-plugin-ejs-template/EjsAsset.js:30:12)
at <anonymous>
Run Code Online (Sandbox Code Playgroud)
Where items is just a list of products that I am sending from back-end with res.render() in order to create a drop-down.
Any help would be appreciated.
| 归档时间: |
|
| 查看次数: |
629 次 |
| 最近记录: |