question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default moxios import doesn't work in TypeScript

See original GitHub issue

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;

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:6

github_iconTop GitHub Comments

4reactions
gynetcommented, May 2, 2018

Guys, here is my current workaround,

import * as moxios from “moxios”;

0reactions
anilanarcommented, May 27, 2018

Kamino cloned this issue to anilanar/moxios

Read more comments on GitHub >

github_iconTop Results From Across the Web

I'm not able to use Axios in TypeScript - Stack Overflow
1- First I made index.ts file import axios from "axios"; const url = "https://jsonplaceholder.typicode.com/users/2"; axios.get(url). · 2- Then I ...
Read more >
axios - npm
axios. TypeScript icon, indicating that this package has built-in ... If you use require for importing, only default export is available:.
Read more >
What is Typescript? Why bother? - Medium
Here we will organize and print out that data, utilizing some very basic TypeScript: // index.tsimport axios from 'axios';const url ...
Read more >
Module not found: Can't resolve 'axios' in React | bobbyhadz
If you still get the "Module not found: Error: Can't resolve 'axios'" error, open your package.json file and make sure it contains the...
Read more >
Understanding Axios.create - LogRocket Blog
It merges the default and provides a custom config for the newly-created instance of Axios. Similar to using Axios with require or import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found