Registry / devops / axios-miniprogram-adapter

axios-miniprogram-adapter

JSON →
library0.3.5jsnpmunverified

Axios adapter for miniprogram (WeChat, Alipay, DingTalk, Baidu). Current stable version: 0.3.5. Release cadence: irregular, with last update around 2020. Provides a drop-in adapter so developers can reuse axios code across web and miniprogram platforms. Unlike using raw wx.request, it enables axios features like interceptors, transformRequest/Response, and cancellation. Supports TypeScript. Minimal bundle increase (~2KB). Active but low maintenance.

npm install axios-miniprogram-adapter
INSTALL
IMPORT
SIG · AXIOS-MINIPROGRAM-
A
axios-miniprogram-adapter
devopsjavascriptv0.3.5
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.

default
import mpAdapter from 'axios-miniprogram-adapter'
const mpAdapter = require('axios-miniprogram-adapter')
ESM default export. Also works with CJS require, but import is recommended.
mpAdapter
axios.defaults.adapter = mpAdapter
axios.defaults.adapter = mpAdapter()
Assign the function itself, not its return value.
config transformer
mpAdapter(config, { transformRequestOption: fn })
mpAdapter(config, fn)
Second argument must be an object with transformRequestOption key.
types
import type { MpAdapterOptions } from 'axios-miniprogram-adapter'
TypeScript type available for the options object.

Sets up axios adapter for miniprogram and makes a GET request with basic configuration.

// Ensure axios and adapter are installed // $ npm i axios axios-miniprogram-adapter import axios from 'axios' import mpAdapter from 'axios-miniprogram-adapter' // Set as default adapter axios.defaults.adapter = mpAdapter // Use axios as usual inside miniprogram axios.get('https://api.example.com/data', { params: { key: process.env.KEY ?? '' } }).then(response => { console.log(response.data) }).catch(error => { console.error(error) }) // With custom request option transformation const customAdapter = config => mpAdapter(config, { transformRequestOption: requestOption => { // Modify request option (e.g., add header) requestOption.header = { ...requestOption.header, 'X-Custom': 'value' } return requestOption } }) axios.defaults.adapter = customAdapter
Debug
Known issues
gotchaAdapter must be set before any requests are made.
fix
Set axios.defaults.adapter = mpAdapter immediately after import.
affects: >=0.0.0
gotchaWhen using CJS require, ensure axios version 0.21.0+ for stable peer compatibility.
fix
Upgrade axios to >=0.21.0 and axios-miniprogram-adapter to >=0.3.0.
affects: <0.3.0
gotchaThe adapter does not support all axios features like XMLHttpRequest-specific options (onUploadProgress).
fix
Use miniprogram native methods for progress events via transformRequestOption.
affects: >=0.0.0
deprecatedThe package is not actively maintained; last update was 2020. Use with caution.
fix
Consider alternative adapters or maintain a fork if issues arise.
affects: <=0.3.5
Errors
Common errors & fixes
Cannot find module 'axios/lib/utils'
Miniprogram npm doesn't resolve nested dependencies of module correctly when not using webpack.
fix
Use webpack or copy the bundled dist file directly (recommended: use npm with webpack).
TypeError: adapter is not a function
Assigning mpAdapter() (called function) instead of mpAdapter (function reference).
fix
Change to: axios.defaults.adapter = mpAdapter
Request failed with status 0
Request blocked by miniprogram domain whitelist or HTTPS requirement.
fix
Ensure the request URL is in the whitelist in miniprogram admin settings. Use HTTPS URLs.
Upgrade
Version history
0.3.5latest on npm
Audit
Dependencies
axiosrequiredpeer dependency – adapter works with axios instance
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
axios-miniprogram-adapter — npm install axios-miniprogram-adapter · libregistry