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

Incorrect "No default export found" #850

Closed
jer-sen opened this issue May 26, 2017 · 11 comments
Closed

Incorrect "No default export found" #850

jer-sen opened this issue May 26, 2017 · 11 comments
Labels

Comments

@jer-sen
Copy link

jer-sen commented May 26, 2017

Hello,

I get an incorrect "No default export found" error when importing "react-native-code-push".
Source code of this module is here : https://github.com/Microsoft/react-native-code-push/blob/master/CodePush.js

It would be great if you could fix this.

Thanks in advance.

@ljharb
Copy link
Member

ljharb commented May 26, 2017

How are you importing it?

Since that module.exports is an object, the implication is that you should be named-importing it's properties as you need then.

@jer-sen
Copy link
Author

jer-sen commented May 27, 2017

import codePush from "react-native-code-push";
codePush.codePushFunction(blabla);

... so with a default import which is working well.

@ljharb
Copy link
Member

ljharb commented May 27, 2017

If you try import { codePushFunction } from 'react-native-code-push';, would it work as well, but without the linter complaining?

@Sparragus
Copy link

Sparragus commented May 30, 2017

The same also happens with import Swiper from 'react-native-swiper. See https://github.com/leecade/react-native-swiper/blob/master/index.js

How can I help debug and fix this?

@ljharb
Copy link
Member

ljharb commented May 30, 2017

hmm, that one is just a function, so that should work fine.

@Sparragus any chance you could make a small repo that reproduces the problem?

@Sparragus
Copy link

@ljharb Sure. Will reply with it later.

@Sparragus
Copy link

Sparragus commented May 30, 2017

@ljharb Here you go: https://github.com/Sparragus/eslint-plugin-import-bug

I also added another case. It's having trouble with https://github.com/react-native-training/react-native-elements/blob/master/src/index.js too.

I added a README with instructions on how to reproduce. Let me know if it worked.

@ljharb
Copy link
Member

ljharb commented May 31, 2017

Eesh, both of those are publishing untranspiled code.

Either way, react-native-elements has no named exports - that's explicitly using module.exports = which means you have to import that as an object, and then in a separate line, destructure out what you need.

I'm not sure why react-native-swiper isn't working.

However, I'm super confused why either of those packages publish untranspiled import but don't use export directly in their entry points.

@jer-sen
Copy link
Author

jer-sen commented Jun 1, 2017

@ljharb linter still complains with import { codePushFunction } from 'react-native-code-push';

@ljharb
Copy link
Member

ljharb commented Jun 1, 2017

@Jay1337 react-native-code-push also publishes untranspiled code.

eslint-plugin-import might need a custom resolver for untranspiled code. Sadly, react-native encourages publishing untranspiled code, which breaks every non-react-native user.

@benmosher
Copy link
Member

benmosher commented Jun 28, 2017

since the imported module is a valid ES module (has imports), it is expected to export something.

the linter is correct: there is no default export.

is this sort of module typical? I am unfamiliar with this usage of CJS export with ESM import.

you can import/ignore it to work around.

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

No branches or pull requests

4 participants