【问题标题】:how to fix this Cannot read properties of undefined (reading 'get') from axios in node.js如何解决此无法从 node.js 中的 axios 读取未定义的属性(读取 \'get\')
【发布时间】:2022-11-13 03:21:19
【问题描述】:

我尝试在 node.js 中使用 axios 和 common.js

包括错误无法读取未定义的属性(读取“获取”)

  • Axios 1.1.3
  • Node.js 16.15.0
const axios = require("axios").default;

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

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

我试试这个

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

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

test().then((res) => console.log(res.data)) // response => Cannot read properties of undefined (reading 'get')

【问题讨论】:

    标签: javascript node.js


    【解决方案1】:
    const axios = require('axios')
    

    这将解决问题

    【讨论】:

    • 是的,但在 vscode 中不要向我显示建议,这还不错,但如果我使用默认值,我可以看到来自 axios 的所有建议(获取、发布、创建......)
    猜你喜欢
    • 2020-06-20
    • 2020-12-18
    • 2022-01-26
    • 2022-10-19
    • 2019-04-30
    • 1970-01-01
    • 2021-05-10
    • 2019-09-21
    • 2021-11-14
    相关资源
    最近更新 更多