【React】配置react-hot-loader后出现import' and 'export' may only appear at the top level

来源:互联网 发布:香橙派 ubuntu 编辑:程序博客网 时间:2024/05/19 11:48

在搭建React开发环境是使用react-hot-loader时出现了import' and 'export' may only appear at the top level错误,当时考虑到使用的版本存在问题,通过官方git发现如下办法解决;

解决办法:

If you're using React Hot Loader together with Babel (ex 6to5), make sure React Hot Loader stays to the left of Babel inloaders array in Webpack config

大致意思是在使用Babel时如果版本大于5之后需要将react-hot-loader放在babel-loader的前面,调整顺序之后,执行编译名称果然错误不存在了。

但是产生了 ./node_modules/react-pure-render/function.js错误,通过错误信息可以知道jsx时去编译了node_modules文件夹下的js文件,可以在添加include或exclude属性来指定或排除不需要编译的文件夹

rules: [{
    test: /\.jsx?$/,
    include: path.join(__dirname, 'src'),
    loader: ['react-hot-loader', 'babel-loader']
},

原创粉丝点击