82

Look

Webstorm doesn't recognize one of my .js files as a JavaScript file so I'm losing syntax highlighting and being able to add break points. I've looked in the workspace.xml file and the file in question seems to have similar settings to other .js files that work correctly.

If I change the name of the file it works ok. So somehow Webstorm is stuck on misinterpreting the type of a file that has this name. Where else can I edit the project?

Context menu

5
  • may be broken indexes — try to run 'File -> Invalidate Caches...' Commented Nov 11, 2014 at 20:51
  • I did invalidate+restart but no change unfortunately. Commented Nov 11, 2014 at 21:19
  • Do you have the action 'Mark as JavaScript' in context menu for the file? Commented Nov 11, 2014 at 22:12
  • I've added the context to the question. Its big! Commented Nov 11, 2014 at 22:36
  • None of the answers so far worked for me. I renamed the file and it was recognized as JS. Commented Jan 4, 2018 at 21:25

11 Answers 11

196

So I see three possible reasons for the problem:

  1. The file was marked as 'Plain text'

  2. There is a pattern for 'Text files' file type that matches this file (or back: file type 'JavaScript' exclude this file name). See image below

enter image description here

  1. There is a custom plugin that overrides default behavior for files with this name (unlikely)

Updated: after several years I've found one more reason for the behavior and most likely it the main source of the issues. When you create a file without any extensions the "Register New File Type Association" is appeared. And you can accidentally specify a new file type, for some file name. It is can be fixed with (2) but it is the reason why the pattern was added there.

Register New File Type Association

Note: the solution works for all IDEA-based IDEs: IntelliJ IDEA, WebStorm, RubyMine, PyCharm, PhpStorm.

Sign up to request clarification or add additional context in comments.

8 Comments

I think 1) is most likely because I messed up creating it as a js file to begin with. How do I mark it correctly?
@IanWarburton It's #2 for sure -- #1 will have slightly different file icon. Especially considering your latest comment "I messed up creating it as a js file to begin with"
This is fairly easy to do. If you 'New' a generic file and forget to put the extension in the dialog it switches to defining a pattern. If you then type the extension in you've defined a new kind of text file!
Note that this also applies to IntelliJ IDEA (see youtrack.jetbrains.com/issue/WEB-19160)
this was the answer for me. i had created a new file without an extension, and when prompted on the file type in the next dialog i added an extension instead of choosing one from the list. at that point intellij "helpfully" added my new file to the Text files list :/
|
19

File -> Settings -> Editor -> FileTypes -> Text files -> check for "ContentRepository.js" pattern there and remove it.

Comments

13

If the file was marked as "Plain Text", then this can be fixed as follows:

  1. Right click on the file.

  2. One of the menu options is "Mark as Javascript" . Just below "Delete".

  3. Click that. Your file is now recognized as javascript by WebStorm.

Since WebStorm was not allowing screenshots after right click so couldn't add it here.

Comments

6

My problem was with Auto-detect file type by context

enter image description here

1 Comment

On Ubuntu the tag is called 'File type auto-detected by content'
3

For me this did the trick
1) Preferences
2) Editor
3) FileTypes
4) Search for javascript
5) Add *.js to registered patterns

Comments

1

You can also try "Template data languages" (in file > settings) which will force a specific language synatax high-lighting on a specific file or folder. See screenshot belowenter image description here

For a block of code you can also use "language injection". Simply high-light the block of code, wait for the little lamp to appear then select the bottom choice and then the language you need (screenshot also attached)

enter image description here

Comments

1

enter image description here enter image description here

2022 update!

Right click on file and choose JavaScript

Comments

0

In case it is helpful elsewhere (OMG this was scary).

For some reason IntelliJ was not recognizing any .js file in my project (even after .idea removal (rm -rf .idea)).

I went to Webstorm (in my case RubyMine): Webstorm > Preferences ... > Editor > File Types then went to Recognized Filed Types, picked Javascript (but whatever file type you are missing will do), then added back a Registered Patterns entry of *.js

Of course, press Apply and then Ok.

Wow, scary stuff. but solved my problem, hope it does for someone else.

Comments

0

I was always trying to add .js as a recognised file types, but somehow .js was added to Ignored Files and Folders.

I just removed .js from Ignored Files and Folders and it worked for me.

  1. Preferences
  2. Editor
  3. FileTypes
  4. Ignored Files and Folders
  5. Remove *.js

WebStorm -- Ignored Files and Folders

Comments

0

I had a strange case where none of the other answers here worked for me but then I remembered how I had created the file.

I had tried to be clever and used the following command

mkdir __tests__ && touch "${_}/index.test.js

The shell prompted me to complete the double quote and that was fine. I was able to load the file in IntelliJ Idea, but I was very confused as to why it was not getting javascript syntax highlighting. I tried to change the file association, but no luck.

Then I thought I would just delete the file and try to re-create it. When I typed the rm command I hit tab to autocomplete the file path and saw my problem:

rm __tests__/index.test.js$'\n'

Because I had hit enter before completing the double-quote in the command to create the file, the file was named index.test.js\n. IntelliJ Idea was happy to open the file and displayed it as index.test.js, but the extension was .js\n, not simply .js, hence it did not recognise the file as a .js file.

A rename would likely have worked, but I just deleted it and re-created it, this time without the \n at the end.

Comments

0

Copy the file, delete it using Windows Explorer and paste it again in the folder (DataAccess).

Surprise! Now Webstorm recognizes it...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.