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

Node.js(CommonJS)中Axios报Cannot read properties of undefined (reading 'get')的解决

Node.js 16.15.0 + Axios 1.1.3: 解决"Cannot read properties of undefined (reading 'get')"错误

在Node.js 16.15.0环境下使用CommonJS规范引入Axios 1.1.3时,调用axios.get出现Cannot read properties of undefined (reading 'get')错误,可通过以下几种方式排查解决:

1. 重新安装Axios,确保依赖完整

可能是Axios安装不完整导致模块导出异常,执行以下命令重新安装指定版本:

npm uninstall axios
npm install axios@1.1.3

2. 调整Axios的引入方式

CommonJS环境下Axios的导出结构可能因版本细节存在差异,尝试以下两种引入写法:

写法一:单独提取default实例

const axios = require("axios");
const axiosInstance = axios.default;

async function test(){
    const data = await axiosInstance.get("https://www.google.com")
    return data
}

test().then((res) => console.log(res.data))

写法二:直接解构get方法

const { get } = require("axios");

async function test(){
    const data = await get("https://www.google.com")
    return data
}

test().then((res) => console.log(res.data))

3. 排查模块引入冲突

确认项目根目录下不存在名为axios.js、axios的文件夹,避免Node.js错误地引入本地文件而非npm安装的依赖包。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 08:15:46