最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React export declaration statement expected - Stack Overflow

programmeradmin1浏览0评论

When I try to export my ponent my editor show me an error export declaration statement expected

here is my code:

export Header from './Header/Header';

but if I do this:

export {default as Header} from './Header/Header';

it doesn't show any error.

my Header.js

export default class Header extends React.Component {
  //code
}

I'm following this example .js

My ponent folder structure and export method same like those link.

Any solution?

When I try to export my ponent my editor show me an error export declaration statement expected

here is my code:

export Header from './Header/Header';

but if I do this:

export {default as Header} from './Header/Header';

it doesn't show any error.

my Header.js

export default class Header extends React.Component {
  //code
}

I'm following this example https://github./erikras/react-redux-universal-hot-example/blob/master/src/ponents/index.js

My ponent folder structure and export method same like those link.

Any solution?

Share Improve this question asked Apr 19, 2017 at 4:13 ssuhatssuhat 7,66620 gold badges67 silver badges123 bronze badges 2
  • export {default as Header} from './Header/Header'; looks right to me. What's the issue with that? – Felix Kling Commented Apr 19, 2017 at 4:37
  • @Felix Kling no issues. I'm curious why at the link I post, there's no issue – ssuhat Commented Apr 19, 2017 at 4:40
Add a ment  | 

2 Answers 2

Reset to default 8

Any solution?

export Header from './Header/Header'; is not valid syntax, however there exists a proposal to support it.

The repository you linked to configured babel to support this proposed feature by using the stage-0 preset:

{
  "presets": ["react", "es2015", "stage-0"],
  ...
}

stage-0 includes stage-1 which contains the transform-export-extensions plugin that implements this feature.


But to be clear, you don't have to use this experimental feature.

export {default as Header} from './Header/Header';

has the same effect and is standard ES6.

Try export default from './Header/Header';

发布评论

评论列表(0)

  1. 暂无评论