Alejandro
Alejandro

Reputation: 637

TypeError: axios.request is not a function

The following statement is giving me a err: TypeError: axios.request is not a function when I run the api.

const content = await axios.request(getData(id)).then(res => res.data)

Where getData returns a configuration object.

I am importing axios like so: import * as axios from 'axios'

Upvotes: 1

Views: 19833

Answers (2)

Vikram Rajput
Vikram Rajput

Reputation: 101

@deerawan's Answer looks correct.

but still you are confused you can refer axios reference page.

https://kapeli.com/cheat_sheets/Axios.docset/Contents/Resources/Documents/index

Upvotes: 0

deerawan
deerawan

Reputation: 8443

When we look at axios type definition file, we can see that it uses default export. So, instead of using import * as axios from axios, the correct way is using import for default.

import axios from 'axios'

axios.request({ // params });

Tested in vscode, it didn't give compile error.

enter image description here

Hope it helps.

Upvotes: 2

Related Questions