反应导出意外令牌 [英] react export Unexpected token
问题描述
所以我有这些文件和文件夹.
So I have these file and folder.
App.js
modules/
user/
index.js
list.js
在list.js中,我有 export default(props)=>(...)
In list.js I have export default (props) => (...)
在index.js中,我从'./list'中 export UserList;
In index.js I have export UserList from './list';
在App.js中,我从'./modules/user';
And in App.js I have import { UserList } from './modules/user';
那里有什么问题吗?因为我有
Is there something wrong there? Because I got
./src/modules/user/index.js
Syntax error: Unexpected token, expected { (1:7)
> 1 | export UserList from './list';
但是我看不出这是怎么回事?救命!
But I don't see what's wrong here? Help!
这是我的list.js文件的更多详细信息,但我认为它没有什么不同,因为错误在index.js中
Here's more details of my list.js file, but I don't think it makes a difference because the error is in index.js
import React from 'react';
// more import
export default (props) => (
<List {...props}>
...
</List>
);
推荐答案
我看到您正在直接导出属于另一个文件的组件而不导入它.
I see you are exporting the component directly which belongs to another file without importing it.
您的操作方式是 ES8提案
在ES6中,您可以将组件导出为
In ES6, you could export the component as
export {default as UserList} from './list'
然后导入为
import { UserList } from './modules/user';
这篇关于反应导出意外令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!