You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用Visual Studio 2017自动注入import语句?

Fixing Automatic Dependency Injection in Visual Studio 2017 for Local JS Files

Hey there, I’ve run into similar quirks with VS 2017’s JavaScript tooling before—let’s walk through how to stop those unwanted auto-injected lines when you use functions like clearTimeout.

Possible Causes

This is almost always triggered by either a third-party extension you’ve installed, or Visual Studio’s built-in JavaScript/TypeScript Language Service trying to "help" by adding what it thinks are missing dependencies.

Step-by-Step Solutions

  • Disable Suspect Extensions
    Since you mentioned having several extensions installed, start by narrowing down which one might be causing this:

    1. Go to Tools > Extensions and Updates
    2. Navigate to the Installed tab, filter for JavaScript-related extensions
    3. Disable one extension at a time, restart VS, then test by adding clearTimeout to your file
    4. Repeat until the auto-injection stops—you’ve found the culprit (you can either keep it disabled or check for updates for that extension)
  • Turn Off Auto-Import in Language Service Settings
    VS 2017’s built-in JS tooling has auto-import features that might be misfiring for local files:

    1. Open Tools > Options > Text Editor > JavaScript/TypeScript > Language Service
    2. Look for options like "Auto-import modules" or "Add missing imports"
    3. Uncheck these options, click OK, and restart VS to apply changes
  • Mark Files as Non-Module (if applicable)
    If VS is treating your local JS file as a module (even if it’s not), it might try to inject dependencies. Add this comment at the very top of your file to tell VS to skip module-related auto-processing:

    // @ts-nocheck
    // @noflow
    

    Alternatively, remove any accidental import/export statements that might be triggering module mode.

  • Reset Visual Studio Settings
    If all else fails, resetting your VS settings to default can eliminate misconfigured options:

    1. Go to Tools > Import and Export Settings
    2. Select "Reset all settings", follow the prompts to back up your current settings first
    3. After resetting, test the issue again

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:01:43