question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property 'get' does not exist on type 'typeof Axios'.

See original GitHub issue

Whan I use axios with TypeScript, I got this error

Property 'get' does not exist on type 'typeof Axios'.

I tried some solutions like here but I still get above error

And my code is like this

import React from 'react'
import axios from "axios";

class Home extends React.Component {
  constructor(props:any) {
    super(props)
  }

  componentDidMount() {
    axios.get("url").then((res:any) => console.log(res,"res"))
  }

  render() {
    return <SomeComponents/>
  }
}

export default Home

Any Solution?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

19reactions
coolaj86commented, Aug 27, 2021

I’m having the same problem in my project with JSDoc and axios, but "moduleResolution": "node" didn’t seem to solve the problem.

I tried to only change the minimal required amount from the tsc --init defaults:

  • allowJs: true
  • checkJs: true
  • noEmit: true
  • moduleResolution: “node”
  • typeRoots: [“./typings”, “node_modules/@types”]
  • include: [“**/*.js”]
  • exclude: [“node_modules”]
{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "allowJs": true,
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "alwaysStrict": true,
    "noImplicitReturns": true,
    "moduleResolution": "node",
    "typeRoots": ["./typings", "node_modules/@types"],
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["**/*.js"],
  "exclude": ["node_modules"]
}

It seems to recognize stuff in node_modules/@types just fine.

Update

Seems like it was the default export issue:

var axios = require('axios').default;

For some modules you have to get a little more creative:

//@ts-ignore
require('axios-retry').default = require('axios-retry');
var axiosRetry = require('axios-retry').default;

More explanation: https://github.com/BeyondCodeBootcamp/jsdoc-typescript-starter/

14reactions
rvritacommented, Sep 11, 2022

I fixed this by using import { default as axios } from 'axios'.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'create' does not exist on type - Stack Overflow
I am trying to contact an API but when I use axios.create() I get an error saying: Property 'create' does not exist on...
Read more >
property 'get' does not exist on type 'typeof axios' - You.com
Hello, i work with Angular, and i want to use axios to work with but the get function "does not exist". My code...
Read more >
Property 'create' does not exist on type 'typeof import("/Users ...
While converting existing project to TS I'm getting an error: Property 'create' does not exist on type 'typeof import("/Users/my-path/node_ ...
Read more >
关于Property 'create' does not exist on type 'typeof ... - 博客园
在 Vue 项目中的 src 目录下新建 axios.d.ts 文件并键入以下代码,并重新编译运行。 ... 关于博主: 评论和私信会在第一时间回复。或者直接私信我。
Read more >
Property 'Provider' does not exist on type 'typeof import.ts(2339)
Property 'wallet' does not exist on type 'Provider'.ts(2339) | Property 'Provider' does not exist on type 'typeof ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found