Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emmet autocomplete is not functioning in JSX

I'm new to Visual Studio Code and trying to get emmet to work on JSX. I read that I had to use the following code in my settings, but it is still not working. Can anyone troubleshoot for me?

"emmet.includeLanguages": {
      "html": "html",
      "javascript": "javascriptreact",
      "xml": {
        "attr_quotes": "single"
      }
    },
    "emmet.triggerExpansionOnTab": true 
}
like image 519
user7392290 Avatar asked Jul 31 '18 15:07

user7392290


People also ask

How do I enable Emmet in JSX?

Go to settings > extensions > emmet > include languages and add javascript as the item and javascriptreact as the value.

Does Emmet work with JSX?

Emmet does not work in js/jsx files for VS Code 1.62.

Does Emmet work in .JS files?

Emmets don't work in JS files. However, you can set it so that VS Code thinks that it's a JSX file and it would give React IntelliSense.

How do you add Emmet in React?

Easy way to enable emmet for React It's already included for all HTML and CSS files by default in VS code but we need to do some extra configuration to enable it for React. 4. Once opened, add "javascript": "javascriptreact" under “ emmet. includeLanguages ” and save the file.

How do I enable Emmet autocompletion inside a react file?

In VSCode, Emmet is built-in, so it works out of the box when you want to do autocompletion inside your .html files. But when you’re inside a React file, this autocompletion doesn’t always work. In that case, you’ll have to enable Emmet’s triggerExpansionOnTab function manually inside your project’s Workspace Settings.

Is it possible to enable Emmet by default in JS?

this is the recommended way to do it, we do not want to enable emmet by default in JS. Then you are missing features like jump to symbol etc that you get with "Javascript". this should not be the case, since the same language service/parser is used for .js and .jsx files.

How to make Emmet expansions work in TTS files?

@admmasters Emmet expansions are working fine in .tsx files. For it to work in .ts files you need to either map "typescript" to "jsx" in emmet.syntaxProfiles or change language mode to tyspescriptreact Sorry, something went wrong.

How do I use Emmet in VSCode?

For example, typing h1 followed by hitting the TAB key (on your keyboard) will automatically create a complete h1 element (open/close tags) <h1></h1> and thus save you a lot of typing. In VSCode, Emmet is built-in, so it works out of the box when you want to do autocompletion inside your .html files.


2 Answers

This works for me:

"emmet.includeLanguages": {
  "html": "html",
  "javascript": "javascriptreact",
  "xml": {
    "attr_quotes": "single"
  }
},
"emmet.triggerExpansionOnTab": true

The only difference to your code is I removed the last curly brace so it is properly contained within the settings.json object. If you want these settings to work with all your files and projects make sure the changes are in your USER SETTINGS.

Here is the VSCode related documentation for Emmet configuration.

like image 86
PatrickOlvera Avatar answered Oct 13 '22 01:10

PatrickOlvera


i found out that sometimes Emmet "forgets" to look for HTML in JS files, but it still does work in JSX and CSS files. So I put a few lines to "remind" Emmet look HTML in js files as well, associate with them, here it is:

"emmet.triggerExpansionOnTab": true,
"emmet.includeLanguages": {
    "javascript": "javascriptreact"
}

or this:

"emmet.triggerExpansionOnTab": true,
"files.associations": { "*.js": "javascriptreact" }

here is the source

like image 22
Alexey Nikonov Avatar answered Oct 13 '22 01:10

Alexey Nikonov