Visual Studio Code isn't recognising EJS
Asked Answered
I

9

10

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.

Interested answered 8/12, 2019 at 17:48 Comment(2)
Try restarting Visual Studio Code; let me know if that works. I've gotten similar issues beforeVariolous
@Variolous Unfortunately, that did not work. It still isn't showing up in the list of languages.Interested
P
17

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.

Praxis answered 9/12, 2019 at 9:34 Comment(4)
I have installed the plugin, but EJS does not show up in the language list. Is there something else I need to do?Interested
This did nothing for me unfortunately, even after reloading vscode.Whitherward
Nothing happenedTamatamable
Installing EJS Language Support worked for me as this answer is already set by defaultCanfield
H
14

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 😎

Hermaphroditus answered 4/9, 2021 at 11:42 Comment(1)
This solved it for me, works with ejs and Tailwind.Kif
H
7

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.

Haemachrome answered 8/6, 2020 at 3:27 Comment(0)
R
1

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
Reflux answered 9/12, 2019 at 9:41 Comment(0)
K
0

I found the solution (how to setup VSCode, no troubles):

  1. Install EJS language support plugin
  2. Now you have ejs support, highlighting, and snippets, but some tags like
<? for( let item of array ) { ?>
(some data)
<? } ?>

are formatted incorrectly (at least with default html formatter).

  1. To fix this, you can try set custom delimeter to '?' ejs.delimeter = '?'. Now you have correct indentation with <? ... ?> tags.
  2. To use the snippets with our custom delimeter, you need to edit extension snippets (or add your own): install Snippets Ranger plugin, then find needed extension and edit its file. The Snippets Ranger is very handy tool.
  3. If, for some reason, you still don't have what you want, try configure file association to html: Ctrl+Shift+P => Change language mode => set HTML

I hope I helped somebody to setup VSCode for .ejs files

Kelsiekelso answered 4/1, 2021 at 15:56 Comment(0)
P
0

What worked for me, I followed the exact sets shown by Al Mahdi above; but I did not get the option to change the file to ejs. So what I did was renamed the file in the Explorer tab in VS code to "filename.ejs" which was in a views folder(not sure if you did this step). Then everything worked perfectly fine for me.

enter image description here"

Penzance answered 14/11, 2021 at 2:42 Comment(0)
N
0

folder link, not file link

I admit I was clicking on a folder link too quickly created in the Explorer sidebar like "views\pages\index.esj", so ensure you created a file, not a folder :)

Niece answered 18/6, 2022 at 15:49 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Wilkes
M
0
  1. Head over to https://marketplace.visualstudio.com/items?itemName=DigitalBrainstem.javascript-ejs-support and install EJS Language support

  2. Click on ctr + shift + p and search for settings.json

  3. Past this below:

"emmet.includeLanguages": {
  "ejs": "html"
},
"html.format.templating": true
  1. Make sure there isn't error or misspelling in your code

  2. Reload your windows and BOOM! error is solved! : )

Maidenhair answered 15/7, 2022 at 0:52 Comment(0)
J
0

tried everything and finally fixed downloading the following extension - EJS Language Support -

https://marketplace.visualstudio.com/items?itemName=leonzalion.vscode-ejs

EJS Language Support

add these code to settings.json in vscode

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

"emmet.includeLanguages": {
 "ejs": "html",
 },

"html.format.templating": true
Jiggerypokery answered 25/2 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.