lifeomic/axios-fetch

Unable to import useAxiosFetch as an ES6 module

kushniryb opened this issue · 1 comments

Hello guys, hope you are well!
First of, thanks for developing this awesome library, much appreciated! ❤️

I'm trying to import useAxiosFetch in my React app as an ES6 module:
import { useAxiosFetch } from '@lifeomic/axios-fetch'

Unfortunately, I'm getting the following error:

fromRequireContextWithGlobalFallback.js:21 ReferenceError: exports is not defined
    at Module../node_modules/@lifeomic/axios-fetch/src/index.js (index.js:15)

Lines causing error:

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

Could you please let me know what could be the cause of it?

I'm using v2.0 with Webpack. Let me know if you need me to provide any additional details.

The common use case for us is to use axios-fetch in Node code. I haven't seen that issue before.

I have a feeling you are hitting that because you have some very "pure", ES6 only, code and webpack config. The axios-fetch project doesn't export a ES6 version of the library, so your bundler is not happy to see the commonjs exports reference.

As a hack, could you try adding a "type": "commonjs" entry to the package.json in axios-fetch? Looking at https://webpack.js.org/api/module-methods/ that might help and if it does, then we could add that to the npm module we publish