Search code examples
javascriptnode.jsejs

writing ejs in a script is giving me the error 'Expression expected'


I have a script tag in my show.ejs file, and I have the following line:

<script>
    const post = <%- JSON.stringify(post) %>
</script>

I'm getting the error of 'Error Expected' on both the opening and closing ejs tags. I was wondering why this error occurs and if there was anything I'm doing that isn't allowed.


Solution

  • I just have same issue with VS code if you using VS you need to add to end of settings.json in cofiguration of html this line

    "html.validate.scripts": false,
    

    find html in bottom right find html in bottom right

    then find configure HTML language then find configure HTML language and add line to end of json file and add line to end of json file