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

调用axios.create()提示Property 'create'不存在该如何解决?

解决方案

这个报错通常由三类问题导致,按优先级排查即可:

  • 依赖安装异常或版本过旧
    先卸载现有axios依赖再重装最新稳定版,新版axios已内置TypeScript类型定义,无需额外安装@types/axios:
    npm uninstall axios
    npm install axios@latest
    
  • 导入语法适配问题
    若项目TypeScript配置未开启ESM导入兼容,可以先修改导入语句测试:
    把原代码的import axios from "axios"替换为
    import * as axios from "axios"
    
    修改后你的业务代码无需改动,axios.create()可正常调用。
  • TypeScript编译配置缺失
    打开项目根目录的tsconfig.json,在compilerOptions字段下新增两个配置项:
    {
      "compilerOptions": {
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true
      }
    }
    
    配置完成后重启编辑器的TypeScript服务即可生效,VSCode用户可以按快捷键Ctrl+Shift+P(Mac端为Command+Shift+P),搜索选择「TypeScript: Restart TS Server」。

如果以上步骤执行完还报错,可以删除本地依赖缓存后重新安装:

rm -rf node_modules package-lock.json
npm install

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 12:15:04