You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

VSCode保存时自动删除未使用导入,设置source.organizeImports无效怎么办?

React代码中导入自动删除/无法恢复的问题

问题现象

  • 编写React代码时,仅注释掉某导入语句的使用代码行,保存文件后该导入会被自动删除
  • 取消注释使用代码行并再次保存,导入语句不会被自动重新添加

已尝试但无效的解决配置

曾在settings.json中添加以下配置来禁用保存时整理导入,但未生效:

"editor.codeActionsOnSave": {
    "source.organizeImports": "never"
},

当前环境与完整配置

  • 使用最新版本VSCode
  • 已禁用工作区所有扩展
  • 完整settings.json配置如下:
{
    "workbench.colorTheme": "Default Light Modern",
    "editor.acceptSuggestionOnEnter": "off",
    "editor.inlineSuggest.edits.experimental.enabled": false,
    "editor.inlineSuggest.enabled": false,
    "workbench.startupEditor": "none",
    "editor.acceptSuggestionOnCommitCharacter": false,
    "editor.autoClosingBrackets": "never",
    "explorer.confirmDragAndDrop": false,
    "editor.codeActionsOnSave": {
        "source.organizeImports": "never"
    },
    "notebook.codeActionsOnSave": {},
    "javascript.updateImportsOnPaste.enabled": false,
    "typescript.updateImportsOnPaste.enabled": false,
    "settingsSync.ignoredSettings": []
}

内容的提问来源于stack exchange,提问作者herpderp

火山引擎 最新活动