Default moxios import doesn't work in TypeScript
See original GitHub issueI 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:
- Created 6 years ago
- Reactions:4
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Guys, here is my current workaround,
import * as moxios from “moxios”;
Kamino cloned this issue to anilanar/moxios