• 请不要在回答技术问题时复制粘贴 AI 生成的内容
yiluo
V2EX  ›  程序员

eslint 如何能自动导入缺失的模块?

  •  
  •   yiluo · Apr 25, 2022 · 1957 views
    This topic created in 1506 days ago, the information mentioned may be changed or developed.

    经常会遇到 eslint 报错 no-undef 的错误,但是是因为模块没有导入,怎样能用 eslint 自动导入缺失的模块呢

    2 replies    2022-04-25 23:54:01 +08:00
    ChefIsAwesome
        1
    ChefIsAwesome  
       Apr 25, 2022 via Android
    一个变量没定义能等同于这个变量是没引进去的模块?
    YuTengjing
        2
    YuTengjing  
       Apr 25, 2022
    如果你是用的 VSCode ,并且没开自动保存,可以配置在保存时自动导入:

    ```
    "editor.codeActionsOnSave": [
    "source.addMissingImports"
    ]
    ```

    相关文档: https://code.visualstudio.com/updates/v1_46#_add-all-missing-imports-source-action

    如果你设置了自动保存,一般情况在使用的时候就会自动导入,如果没有,那么你可以使用自动修复,或者修复全部,相关快捷键你直接在快捷键表里面搜 auto fix 和 fix all
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1701 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 16:31 · PVG 00:31 · LAX 09:31 · JFK 12:31
    ♥ Do have faith in what you're doing.