Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import useAxiosFetch as an ES6 module #69

Open
kushniryb opened this issue Apr 19, 2021 · 1 comment
Open

Unable to import useAxiosFetch as an ES6 module #69

kushniryb opened this issue Apr 19, 2021 · 1 comment

Comments

@kushniryb
Copy link

kushniryb commented Apr 19, 2021

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.

@mdlavin
Copy link
Member

mdlavin commented Apr 20, 2021

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

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

No branches or pull requests

2 participants