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

Vite+React+TS环境下@gsap/business导入报错:index.d.ts非模块

解决Vite+React+GSAP+TypeScript环境下@gsap/business类型模块报错问题
  • 重新安装并配置TS类型解析
    先卸载并重新安装@gsap/business,确保包文件完整:

    npm uninstall @gsap/business && npm install @gsap/business
    

    不要手动将types文件加入tsconfig的files数组,改为在compilerOptions的types数组中声明:

    {
      "compilerOptions": {
        // 其他原有配置
        "types": ["@gsap/business"]
      }
    }
    
  • 配置Vite的模块解析
    在vite.config.ts中添加resolve配置,明确@gsap/business的入口文件:

    import { defineConfig } from 'vite';
    import react from '@vitejs/plugin-react';
    
    export default defineConfig({
      plugins: [react()],
      resolve: {
        alias: {
          '@gsap/business': '@gsap/business/dist/gsap.min.js'
        }
      }
    });
    
  • 检查类型文件有效性
    打开node_modules/@gsap/business/types/index.d.ts,确认文件开头存在declare module '@gsap/business'的模块声明。如果缺失,说明包文件损坏或未正确获取商业版授权,需重新获取并安装正版包。

  • 清除缓存重启服务
    删除node_modules/.vite缓存文件夹和tsconfig.tsbuildinfo(若存在),然后重启Vite开发服务器。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 18:30:43