Search code examples
webstorm

How to prevent WebStorm from removing imports?


WebStorm is removing unused imports by default. How can I turn this off?

e.g. if I comment out an imported element, the import statement is auto-deleted. When I comment that element back in, I need to manually insert the necessary import statement again.

Often auto-insert of import statements does not help since WebStorm does not recognize that the element has to be imported...


Solution

  • Unused imports are always removed when optimizing imports, so, if you like to keep them, don't run Code | Optimize imports, and make sure that Optimize Imports is not enabled in Reformat Code dialog: Code | Show Reformat File dialog, clear the Optimize Imports checkbox

    enter image description here