Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Default moxios import doesn't work in TypeScript #16

Closed
anilanar opened this issue May 27, 2018 · 1 comment
Closed

Default moxios import doesn't work in TypeScript #16

anilanar opened this issue May 27, 2018 · 1 comment

Comments

@anilanar
Copy link
Owner

From moxios created by rossenassenov : axios#27

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;
@anilanar
Copy link
Owner Author

This should work now by doing:

import moxios from '@anilanar/moxios'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant