Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SynataxError: Unexpected Indentifier while compiling ejs file

Tags:

node.js

ejs

Does anyone know what the following error is for?

SyntaxError: Unexpected identifier in /home/smart/Downloads/npmPackage/views/test.ejs while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint: https://github.com/RyanZim/EJS-Lint Or, if you meant to create an async function, pass async: true as an option. at new Function () at Template.compile (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:626:12) at Object.compile (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:366:16) at handleCache (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:215:18) at tryHandleCache (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:254:16) at View.exports.renderFile [as engine] (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:459:10) at View.render (/home/smart/Downloads/npmPackage/node_modules/express/lib/view.js:135:8) at tryRender (/home/smart/Downloads/npmPackage/node_modules/express/lib/application.js:640:10) at Function.render (/home/smart/Downloads/npmPackage/node_modules/express/lib/application.js:592:3) at ServerResponse.render (/home/smart/Downloads/npmPackage/node_modules/express/lib/response.js:1012:7) SyntaxError: Unexpected identifier in /home/smart/Downloads/npmPackage/views/test.ejs while compiling ejs

here is my ejs file

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        <% include partials/navbar %>
    <h1>This is a test Page</h1>
</body>
</html>
like image 554
Diksha Goyal Avatar asked Jan 30 '20 05:01

Diksha Goyal


People also ask

What causes the uncaught SyntaxError unexpected identifier error?

In this post, we looked at what causes the Uncaught SyntaxError: Unexpected identifier error and how to fix it. In most cases, it is just code that is not adhering to the JavaScript syntax rules or contains typos. Hopefully, this post has helped you with your code!

What is an uncaught SyntaxError in JavaScript?

What causes this error? Since JavaScript is not a compiled language, you can get syntax errors when running your code. One of these errors is the Uncaught SyntaxError: Unexpected identifier error. In this post, we'll look at what causes this, examples of it, and how to fix it. What causes this error? This error is mainly caused by three things.

Is there a way to reformat HTML in EJS?

this seems obvious, but you can always reformat if you're desperate and use: innerHTML.output += $ {list.name} in backticks, in GET request rather than ejs... if it's a language library bug with ejs. Sorry, something went wrong. This is not a library bug. This works as expected in EJS:


1 Answers

You have to put it with double quotes and have it like a function call. also you should use <%- for includes echo documentation

Your template should look like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        <%- include("./partials/navbar") %>
    <h1>This is a test Page</h1>
</body>
</html>
like image 129
ROOT Avatar answered Jan 03 '23 07:01

ROOT