Webstorm not recognising JavaScript file
Solution 1
So I see three possible reasons for the problem:
-
The file was marked as 'Plain text'
-
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
- 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.
Note: the solution works for all IDEA-based IDEs: IntelliJ IDEA, WebStorm, RubyMine, PyCharm, PhpStorm.
Solution 2
File -> Settings -> Editor -> FileTypes -> Text files -> check for "ContentRepository.js" pattern there and remove it.
Solution 3
If the file was marked as "Plain Text", then this can be fixed as follows:
Right click on the file.
One of the menu options is "Mark as Javascript" . Just below "Delete".
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.
Solution 4
My problem was with Auto-detect file type by context
Solution 5
For me this did the trick
1) Preferences
2) Editor
3) FileTypes
4) Search for javascript
5) Add *.js
to registered patterns
Related videos on Youtube
Ian Warburton
Updated on January 22, 2022Comments
-
Ian Warburton over 2 years
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?
-
anstarovoyt over 9 yearsmay be broken indexes — try to run 'File -> Invalidate Caches...'
-
Ian Warburton over 9 yearsI did invalidate+restart but no change unfortunately.
-
anstarovoyt over 9 yearsDo you have the action 'Mark as JavaScript' in context menu for the file?
-
Ian Warburton over 9 yearsI've added the context to the question. Its big!
-
Max over 6 yearsNone of the answers so far worked for me. I renamed the file and it was recognized as JS.
-
-
Ian Warburton over 9 yearsI think 1) is most likely because I messed up creating it as a js file to begin with. How do I mark it correctly?
-
LazyOne over 9 years@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"
-
Ian Warburton over 9 yearsAha... yes you are correct. I didn't select 'Text Files' when looking at the patterns. Thanks, points well earned.
-
Ian Warburton over 9 yearsThis 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!
-
Roland Ewald over 8 yearsNote that this also applies to IntelliJ IDEA (see youtrack.jetbrains.com/issue/WEB-19160)
-
worc over 7 yearsthis 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 :/
-
blong over 7 yearsI wasn't able to re-open the issue WEB-19160, so I created a new issue: youtrack.jetbrains.com/issue/IDEA-165177
-
meakgoz about 6 yearsFor those who could not understand the solution from the screenshot, see the answer stackoverflow.com/questions/26872024/…
-
MrD about 6 yearsYou saved my day. Thank you!
-
Niko about 5 yearsFinding this made my day!
-
FrankyHollywood over 2 yearsOn Ubuntu the tag is called 'File type auto-detected by content'