ES6 import / export does not behave as expected

I'm not sure if his reaction is native, but these are my versions:

"react-native": "0.46.4", "babel-preset-react-native": "2.1.0",

// src/utils/a.js
export default 'a file works!'

// src/utils/b.js
export default 'b file works!'

// src/utils/index.js
import a from './a'
import b from './b'

export { a, b }

And basically when I try:

import * as utils from 'src/utils'
// or
import { a, b } from 'src/utils'

It returns undefined properties "a" and "b", such as

utils = { a: undefined, b: undefined }

I have no idea what I'm doing wrong here, I think those files a/b.jsdo not load when they should be, one hack that I did earlier was on the listener function utils.auth, where I had to if (auth && auth.listener), and it worked, because, when the application starts, the listener is undefined, but then right after it becomes what it should be.

Edit: It seems that if I try:

// src/utils/index.js
const a = 'a works'
const b = 'b works'

export { a, b }

The result is the same.

+4
4

. , :

import a from 'src/utils/a'

@loganfsmyth, , utils , a. , react-native - .

0

.

index.js :

export {Content} from './Content'
export {FilterSelect} from './FilterSelect'
export {ListItem} from './ListItem'
export {Searchbar} from './Searchbar'
export {Sidebar} from './Sidebar'
export {RequiredArgument} from './RequiredArgument'
export {Loading} from './Loading'
export {ArgumentProvided} from './ArgumentProvided'
export {OverviewBar} from './OverviewBar'
export {Home} from './Home'
export {Layout} from './Layout'

import { Content, FilterSelect, ListItem, Searchbar, Sidebar, Loading, RequiredArgument, ArgumentProvided, OverviewBar} from './components/index.js'
import Layout from './components/Layout''
+2

, :

https://www.webpackbin.com/bins/-KsEA7P7lKOuBugEy1jd

, Babel? (ES2015, STAGE-0,..)

, :

import _a from './a'
import _b from './b'

export { _a as a, _b as b }
+2

"./" 'src'

import * as utils from './src/utils'
// or
import { a, b } from './src/utils'
+1

Source: https://habr.com/ru/post/1684302/


All Articles