Visual Studio Code isn't recognising EJS

10,693

Solution 1

By default VSCode does not have syntax highlighting for EJS template files. You need to install a plugin like this one - EJS language support.

You also need to configure the file association for .ejs files. In order to do so type the following command (using CTRL + SHIFT + P) - Change language mode and then select Configure file association for .ejs, then select HTML from the dropdown.

Solution 2

Finally, I found the cause of this problem.

Foremost of all, I installed the EJS language support extension, then I edited settings.json by adding this lines:

"files.associations": {
    "*.ejs": "html"
},
"emmet.includeLanguages": {
    "ejs": "html"
}

I did all that, and my ejs code still not recognized.

enter image description here


After a while, I found that the responsible for that in my case is the HTMLHint extension (Mike Kaufman).

So, I applied with success one of this 2 solutions:

  • uninstall "HTMLHint".
  • edit settings.json by adding this:

"htmlhint.options": {
    "spec-char-escape": false,
    "doctype-first": false
}

enter image description here

NB: I finally uninstalled the EJS language support extension.

Solution 3

Working solution (September 2021)

  1. Install the EJS language support vscode extension
  1. And add these settings to VScode,

     "files.associations": {
         "*.ejs": "html"
     },
     "emmet.includeLanguages": {
         "ejs": "html",
     },
     "html.format.templating": true
    

Have fun 😎

Solution 4

VS Code does not have pre-installed syntax for EJS. You must download the extension plugin for it. try using the following link:

Or type the following command in the VS Code Terminal:

ext install DigitalBrainstem.javascript-ejs-support
Share:
10,693
William Jones
Author by

William Jones

I code.

Updated on July 28, 2022

Comments

  • William Jones
    William Jones almost 2 years

    I am trying to follow this tutorial and write some code in EJS in VS Code. I ran npm i express ejs as per the video's instructions to install both Express and EJS, and no errors popped up in the console. However, in the bottom right (in the blue bar) it still says HTML, and when I click on this to change the language, EJS doesn't appear in the list.

    Am I missing something here? Is there another step I was meant to follow? Any help would be greatly appreciated.