Search code examples
visual-studio-codeeslintprettier

Prettier removes "React" import on pressing save button ( Ctrl + S ). How to fix this?


On pressing CTRL + S , prettier removes React import from tsx files, assuming its not used in the file.

How to fix this ?

Issue


Solution

  • My tsconfig.json had the following settings:

    {
       "compilerOptions": {
           "jsx": "preserve"
       }
    }
    

    Changing jsx value from preserve to react solved the issue.

    {
       "compilerOptions": {
           "jsx": "react"
       }
    }
    

    Reference : https://github.com/microsoft/vscode/issues/152150#issuecomment-1156717872