Default moxios import doesn't work in TypeScript

This issue has been tracked since 2017-04-21.

I tried using https://www.npmjs.com/package/@types/moxios in TypeScript:

import moxios from 'moxios';

describe('MoxiosTest', () => {

    beforeEach(() => {console.log(moxios); moxios.install();});
    afterEach(() => moxios.uninstall());

    it('test', () => {
        console.log(moxios);
    });
});

and getting error:

TypeError: Cannot read property 'install' of undefined
	    at Context.<anonymous> (webpack:///src/api/testing1.test.js:5:75 <- src/api/testing1.test.js:1926:53)

I think the problem is how moxios gets exported from moxios.js.

I had to modify:

	exports.default = moxios;
	module.exports = exports['default'];

to

	module.exports = moxios;
	module.exports.default = moxios;

in order to get the default import to work.

This is similar to how axios is exported in axios.js:

module.exports = axios;

// Allow use of default import syntax in TypeScript
module.exports.default = axios;
flushentitypacket wrote this answer on 2017-06-02

I think this is technically an issue with the @types/moxios package, since it types for exports.default when moxios assigns to exports.

I do think that this is a good change to allow support for both, though.

flushentitypacket wrote this answer on 2017-06-02
drouhard wrote this answer on 2017-06-19

The PR got merged, so this Issue can be closed. Thanks for your help, @flushentitypacket. Awesome to see this great library get nurtured.

gynet wrote this answer on 2018-05-02

still not working with 0.4.8
TypeError: Cannot read property 'install' of undefined

gynet wrote this answer on 2018-05-02

Guys, here is my current workaround,

import * as moxios from "moxios";

anilanar wrote this answer on 2018-05-27

Kamino cloned this issue to anilanar/moxios

More Details About Repo
Owner Name axios
Repo Name moxios
Full Name axios/moxios
Language JavaScript
Created Date 2016-05-25
Updated Date 2022-12-05
Star Count 1386
Watcher Count 20
Fork Count 85
Issue Count 19

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date