Search code examples
expresssublimetext3ejs

.ejs files in Sublime default to file type "Plain Text"


I'm new to coding and I'm using the Express framework in Sublime.

When I create .ejs files, (for example footer.ejs) for some reason Sublime shows these files as Plain Text files, instead of .ejs files, even though I have NPM installed ejs.

enter image description here

Furthermore, when I click on "Plain text" in the bottom right of Sublime, EJS doesn't show up as an option.

enter image description here

My package.json shows that I have ejs installed: "ejs": "^2.5.9".

Does anyone know what I'm doing wrong? And how I can get .ejs files to automatically default to EJS instead of plain text? Thanks!


Solution

  • The short version of the answer to your question is that installing a package via npm doesn't have any effect on Sublime. In order to add support for EJS to Sublime you need to install a package for it in Sublime.

    Package Control has a couple of packages, EJS and EJS 2 (and maybe also Hyperloop EJS, if that's a thing; I'm unfamiliar with EJS).

    Just at first blush it seems like EJS 2 might be the better first bet; it's been more recently updated and is using the newer sublime-syntax syntax format and seems to support more things. Take that with a grain of salt though, since I have no experience with either one.

    You can select the command Package Control: Install Package from the command palette and then select one of those packages to install it. If you're going to try them both, do it one at a time and use Package Control: Remove Package before installing the next one so that they don't compete with each other.

    If those commands aren't in your command palette, you don't have Package Control installed yet. In that case you can select Install Package Control from the command palette to install PC first. If that doesn't work there are also instructions on how to install it manually.

    Once you have a package installed, you can close and reopen the file to apply the correct syntax, or use the menu as you mention in your question.