5
votes

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>
1

1 Answers

7
votes

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>