Webstorm not recognising JavaScript file

23,301

Solution 1

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.

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:

  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.

Solution 4

My problem was with Auto-detect file type by context

enter image description here

Solution 5

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

Share:
23,301

Related videos on Youtube

Ian Warburton
Author by

Ian Warburton

Updated on January 22, 2022

Comments

  • Ian Warburton
    Ian Warburton over 2 years

    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

    • anstarovoyt
      anstarovoyt over 9 years
      may be broken indexes — try to run 'File -> Invalidate Caches...'
    • Ian Warburton
      Ian Warburton over 9 years
      I did invalidate+restart but no change unfortunately.
    • anstarovoyt
      anstarovoyt over 9 years
      Do you have the action 'Mark as JavaScript' in context menu for the file?
    • Ian Warburton
      Ian Warburton over 9 years
      I've added the context to the question. Its big!
    • Max
      Max over 6 years
      None of the answers so far worked for me. I renamed the file and it was recognized as JS.
  • Ian Warburton
    Ian Warburton over 9 years
    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?
  • LazyOne
    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
    Ian Warburton over 9 years
    Aha... yes you are correct. I didn't select 'Text Files' when looking at the patterns. Thanks, points well earned.
  • Ian Warburton
    Ian Warburton over 9 years
    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!
  • Roland Ewald
    Roland Ewald over 8 years
    Note that this also applies to IntelliJ IDEA (see youtrack.jetbrains.com/issue/WEB-19160)
  • worc
    worc over 7 years
    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 :/
  • blong
    blong over 7 years
    I wasn't able to re-open the issue WEB-19160, so I created a new issue: youtrack.jetbrains.com/issue/IDEA-165177
  • meakgoz
    meakgoz about 6 years
    For those who could not understand the solution from the screenshot, see the answer stackoverflow.com/questions/26872024/…
  • MrD
    MrD about 6 years
    You saved my day. Thank you!
  • Niko
    Niko about 5 years
    Finding this made my day!
  • FrankyHollywood
    FrankyHollywood over 2 years
    On Ubuntu the tag is called 'File type auto-detected by content'