-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
New 'export default' issue in 0.16 #4784
Comments
Hey pietropizzi, thanks for reporting this issue! React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
|
noticed this too. workaround is either to |
About the first issue, React Native 0.16 uses Babel 6 to transpile, which changed lots of things. Can you try it by just using Babel 6, and if the issue persists, report this issue on Babel's bug tracker? About the second issue with |
An update on this issue: My aforementioned code: // constants.js
const constants = {
fetchStates: {
LOADING: 'loading'
}
};
export default constants;
// -------------------------------------------
// In another module
import { fetchStates } from './constants';
console.log(fetchStates.LOADING); should not actually work according to spec and apparently Babel 5 made it work but Babel 6 is stricter. The right way to do the export is: // constants.js
export const fetchStates = {
LOADING: 'loading'
};
// or
const fetchStates = {
LOADING: 'loading'
};
export { fetchStates }; I changed that and now I can live without Inside of jest tests it still does not work. There the only way to make it work now is to change all the named imports to this: import * as constants from './constants';
const { fetchStates } = constants; Inside of tests I unfortunately need to use |
Closing this, since it is only about the tests. Narrowed it down, find more info here #3999 (comment) |
In summary, Babel 6 implements a stricter but correct behavior. It's sort of a pain to migrate but from personal experience if you move entirely to import/export one thing that's nice is that cycles are less of an issue because there is no more clobbering of |
I can reproduce an issue with using
export default
since upgrading to 0.16.The following scenario:
Once this code is transformed and run the error message is
undefined is not an object (evaluating '_constants.fetchStates.LOADING')
What does not seem to work is the following line:
It also does not work with require:
This works though:
Alternatively using
module.exports =
instead ofexport default
works too.These are both not great workarounds, there seems to be something wrong with
export default
in general. I ran into another set of issues when requiring the files from jest tests. The exported object would be nested inside anotherdefault
key.I tried all I can digging into this and trying to find the root cause but boiling it down to this scenario is as far as I came.
The text was updated successfully, but these errors were encountered: