2

I am following The Net Nijna's tutorial on youtube. I reached tutorial number 27, working with partials in ejs. Everything works until I add the <% include partials/nav.js %>, once I add this code I recieve:

SyntaxError: Unexpected identifier in (file location) testapp\views\profile.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 ()..... blah blah blah...

If I remove it, my ejs all works fine.

  <body>
    <% include partials/nav.ejs %>

    <h1>Welcome to the profile of <%= person %> !</h1>
    <p><strong> Age: <%= data.age %></strong></p>

    <p><strong> Job: <%= data.job %></strong></p>
    <p><strong> Pet: <%= data.pet %></strong></p>
    <h2>Hobbies</h2>
    <ul>
      <% data.hobbies.forEach(function(item){ %>
        <li><%= item %></li>
      <%});%>
    </ul>
  </body>

can you help a student out? Thanks a ton!

3
  • 1
    Try <%- include('partials/nav') %> or <%- include partials/nav.ejs %> Commented Dec 31, 2019 at 1:13
  • tried the second one, didn't work but your first one did! BAM! Thanks a bajillion! Commented Dec 31, 2019 at 1:17
  • You're very welcome Commented Dec 31, 2019 at 2:14

3 Answers 3

7

Missing hyphen and need to invoke the include function.

 <%- include('partials/nav') %>
Sign up to request clarification or add additional context in comments.

1 Comment

For readers of Express in Action by Evan Hahn, this fixes an error in the code of the sample app in Chapter 3. Thanks Joseph!
0

I was stuck at the same problem and used -include('#filename'); it worked

Comments

-1

Use: <%- include('folder/file') %>

  • agreeing with @Joseph Varilla
  • Not necessary to include engine extension as this should have been done in app.js or index.js file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.