Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when opening TSX file: Cannot use JSX unless '--jsx' flag is provided #15814

Closed
josh-endries opened this issue Nov 21, 2016 · 5 comments · Fixed by #15925
Closed

Error when opening TSX file: Cannot use JSX unless '--jsx' flag is provided #15814

josh-endries opened this issue Nov 21, 2016 · 5 comments · Fixed by #15925
Assignees
Labels
intellisense-config Intellisense configuration issues typescript Typescript support issues

Comments

@josh-endries
Copy link

  • VSCode Version: 1.7.1
  • OS Version: Windows 8.1

Steps to Reproduce:

  1. Open a TSX file.

This seems kind of ridiculous, given that VSC comes with TS built in. It doesn't know what to do with TSX files? It should automatically add the flag to tsc if it's processing a TSX file.

@mjbvz mjbvz added the typescript Typescript support issues label Nov 21, 2016
@dbaeumer dbaeumer assigned waderyan and unassigned dbaeumer Nov 22, 2016
@zeh
Copy link

zeh commented Nov 22, 2016

I had this intermittently over the past few days (Windows 10 though).

I think I solved it by adding...

"include": [
  "./src/ts/**/*"
]

...to tsconfig.json. Your .ts locations may vary.

@josh-endries
Copy link
Author

Well I worked around it by adding "jsx": "react" to tsconfig.json, as far as I can tell, but that is missing the point.

When you open a TSX file (not a directory), you don't have a tsconfig.json file.

@mjbvz
Copy link
Contributor

mjbvz commented Nov 22, 2016

Ok, I believe the expected behavior would be:

  • If a jsconfig.json or tsconfig.json exists, do nothing. You need to add a "jsx" setting in the config file in that case.
  • For implicit projects, either opening a file directly or opening a directory without a *config.json, assume "jsx": "preserve" for tooling. You would still have to pass a "jsx" setting to actually compile any typescript code in that case, but our tools would work better for most scenarios. If you want to opt into using "jsx": "react", you would need to create a *config.json project file.

Does that sound correct?

mjbvz added a commit to mjbvz/vscode that referenced this issue Nov 22, 2016
Issue microsoft#15814

**Bug**
1. Open a tsx file on its own.
2. See a error about passing `--jsx` to tsc.

**Fix**
For implicit projects, assume `"jsx": "preserve"`.

Closes microsoft#15814
@zeh
Copy link

zeh commented Nov 22, 2016

@mjbvz In my case, the problem was there even though I did have "jsx": "react" inside tsconfig.json already. It was only adding the include parameter that fixed it, I believe*.

(* I say "I believe" because it was really intermittent, so I'm not 100% sure what solved it. It's gone now though)

mjbvz added a commit that referenced this issue Nov 28, 2016
Issue #15814

**Bug**
1. Open a tsx file on its own.
2. See a error about passing `--jsx` to tsc.

**Fix**
For implicit projects, assume `"jsx": "preserve"`.

Closes #15814
@waderyan waderyan added the intellisense-config Intellisense configuration issues label Nov 28, 2016
@scriptmaster
Copy link

scriptmaster commented Sep 22, 2017

Setting tsconfig.json jsx: "preserve" or "react" corrected vscode --jsx defect.

{
  "compilerOptions": {

    "jsx": "preserve",                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */

    }
}

Tip: tsconfig init gives a big list of options where you can easily spot jsx and uncomment.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
intellisense-config Intellisense configuration issues typescript Typescript support issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants