0

I have this file:

AxiosExtension.js

import Axios from 'axios';
//eventually add code here, if I can get this simple file working
export default Axios;

I am running AxiosExtension through webpack babel loader that looks like this:

Webpack Babel-Loader

   {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [
            path.join(__dirname, '../../AxiosExtension'),
        ]
    },

I am including AxiosExtension in multiple files like this:

MyCode.js

import Axios from 'path/to/file/AxiosExtension';

When I load MyCode.js in the browers after building my webpack, I get this error:

Console Error

Uncaught TypeError: window._interopRequireDefault is not a function

When I view my AxiosExtension.js file in Chrome Sources tab, here is what babel has output:

AxiosExtension.js Final Output after Babel

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _axios = require('axios');

window._axios2 = window._interopRequireDefault(_axios);

window._interopRequireDefault = function(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = window._axios2.default;

Looks like _interopRequireDefault is defined after it is used. Any ideas about what might be wrong with my config of webpack/babel?

.babelrc

{
  "presets": ["es2015"]
}
zechdc
  • 3,374
  • 9
  • 40
  • 52
  • What Babel plugins are you using? That function shouldn't be on `window` at all. – loganfsmyth Nov 01 '17 at 03:50
  • @loganfsmyth I added what my .babelrc looks like above. Is that what you mean by plugins? – zechdc Nov 01 '17 at 16:36
  • And what is in `AxiosExtension`? Is that something you wrote, or a third-party thing. – loganfsmyth Nov 01 '17 at 17:10
  • @loganfsmyth `AxiosExtension.js` is exactly what I have included here. It is an import and export statement. That is all right now. Once I get that to work, I'm importing a few other axios files and init them to extend Axios. But I can't get this simple import export working. – zechdc Nov 01 '17 at 17:17
  • Sorry I'm blind I guess :P Maybe some other plugin or Webpack loader you have is screwing things? Babel's behavior does not include `window.` on any of that, and it seems like whatever is changing that to `window.` is breaking it. The expected Babel code can be seen on https://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&code_lz=JYWwDg9gTgLgBAQQB7AgZzgMyhEcDkAhiuvgNwBQA9FQKYButAdjAK6EA2HAnnIQCb84AYwj9acABa0otADRxgmOAEkRhJnADmteDEnAMaUGA4TMwM3ADu0ANbAmWirSSRYccZkKsO8ZKhoZEA&debug=false&circleciRepo=&evaluate=false&lineWrap=true&presets=es2015&targets=&version=6.26.0 – loganfsmyth Nov 01 '17 at 17:38

0 Answers0