Visual Studio Code isn't recognising EJS

不羁的心 提交于 2020-07-23 04:22:05

问题


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.


回答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.




回答2:


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

  • https://marketplace.visualstudio.com/items?itemName=DigitalBrainstem.javascript-ejs-support

Or type the following command in the VS Code Terminal:

ext install DigitalBrainstem.javascript-ejs-support



回答3:


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.


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
}

NB: I finally uninstalled the EJS language support extension.



来源:https://stackoverflow.com/questions/59238175/visual-studio-code-isnt-recognising-ejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!