Registry / messaging / taro-axios

taro-axios

JSON →
library1.1.1jsnpmunverified

A Taro-compatible re-packaging of axios that resolves the browser field issue in Taro's bundler. Current stable version is 1.1.1. It uses Taro's native request adapter instead of XMLHttpRequest, making it work across WeChat Mini Program, Alipay, H5, and other Taro-supported platforms. Ships TypeScript definitions. For Taro 3 use v1.x; for Taro 1/2 use v0.7.0. Differentiator: no browser polyfill needed, supports multipart uploads with custom FileData/PostData classes.

npm install taro-axios
INSTALL
IMPORT
SIG · TARO-AXIOS
T
taro-axios
messagingjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

axios
import { axios } from 'taro-axios'
import axios from 'axios'
Since v0.7.0, you can also use default import: import axios from 'taro-axios'. Named import is recommended for type safety.
PostData
import { PostData } from 'taro-axios'
Use for multipart form data with file uploads.
FileData
import { FileData } from 'taro-axios'
Wraps a file path for upload. Used together with PostData.

Shows how to import axios from taro-axios and make a GET request in a Taro app.

import { axios } from 'taro-axios' async function fetchTodo() { try { const res = await axios.get('https://jsonplaceholder.typicode.com/todos/1') console.log(res.data) } catch (error) { console.error(error) } }
Debug
Known issues
breakingVersion 1.0.0 drops support for Taro 1 and 2. Use v0.7.0 for older Taro versions.
fix
If using Taro 1/2, install taro-axios@0.7.0
affects: >=1.0.0
gotchaNamed import { axios } is required for TypeScript type inference; default import may not provide full types.
fix
Use import { axios } from 'taro-axios' instead of import axios from 'taro-axios' when using TypeScript.
affects: *
gotchaFor file uploads, you must use PostData and FileData classes; plain FormData is not supported.
fix
Use new PostData({ field: new FileData(filePath) }) to construct the request body.
affects: *
Errors
Common errors & fixes
Module not found: Can't resolve 'taro-axios'
Package not installed or wrong Taro version (1/2 vs 3).
fix
Run 'npm install taro-axios' (for Taro 3) or 'npm install taro-axios@0.7.0' (for Taro 1/2).
TypeError: axios is not a function
Importing default export in a CommonJS context where named export is expected.
fix
Use 'import { axios } from 'taro-axios'' instead of 'import axios from 'taro-axios''.
Cannot read property 'post' of undefined
Using default import from older version (before 0.7.0) where only named export exists.
fix
Upgrade to >=0.7.0 or use 'import { axios } from 'taro-axios''.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
@tarojs/tarorequiredPeer dependency; uses Taro adapter for network requests.
Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
taro-axios — npm install taro-axios · libregistry