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

接入JavaScript至TypeScript项目后出现找不到'using'等错误致项目崩溃求助

Fixing "Cannot find name 'using'" and "Cannot find name 'System'" Errors in TypeScript Project

Hey there, sorry to hear your project's crashing after integrating JavaScript files into your TypeScript setup—let's work through these errors one by one to get things back up and running.

1. Resolving "Cannot find name 'using'"

The using keyword is part of ES2022+'s resource management feature and needs specific TypeScript configuration to be recognized:

  • Update TypeScript version: Make sure you're on TypeScript 4.9 or later (this is when native using support was added). Run this command to update:
    npm install typescript@latest --save-dev
    
  • Adjust your tsconfig.json:
    • Set the target option to at least "ES2022" (or "ESNext" for latest features):
      {
        "compilerOptions": {
          "target": "ES2022"
        }
      }
      
    • If you’ve explicitly defined the lib array, ensure it includes "ES2022" to load the necessary type definitions:
      {
        "compilerOptions": {
          "lib": ["ES2022", "DOM"]
        }
      }
      
  • Node.js environment note: If you’re running in Node.js, confirm your Node version is 16.14 or newer (the first version to support using natively).

2. Fixing "Cannot find name 'System'"

System is usually a global variable from SystemJS, and TypeScript doesn’t recognize it by default. Here’s how to fix this:

  • Install SystemJS type definitions: Add the official type declarations to your project with this command:
    npm install @types/systemjs --save-dev
    
  • Load types automatically via tsconfig.json: Add "systemjs" to the types array so TypeScript picks up these definitions globally:
    {
      "compilerOptions": {
        "types": ["systemjs"]
      }
    }
    
  • Manual declaration (for custom System implementations): If you’re using a custom System object, create a .d.ts file (like global.d.ts) in your project root with this basic declaration (expand it to match your implementation):
    declare var System: {
      import: (modulePath: string) => Promise<any>;
      // Add other properties/methods your code uses
    };
    

3. General Setup Checks

  • Ensure TypeScript processes your JS files: Set allowJs to true in tsconfig.json:
    {
      "compilerOptions": {
        "allowJs": true
      }
    }
    
  • If you’re using checkJs (to type-check JS files), consider disabling it temporarily until you resolve these core errors—this will reduce noise while you fix the main issues.

Try these steps in order, and you should see those errors disappear. If you hit any specific snags while implementing these fixes, feel free to share more details about your setup!

内容的提问来源于stack exchange,提问作者Владимир Кавалера

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:36:45