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

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

解决办法:

If you're using React Hot Loader together withBabel(ex 6to5),make sure React Hot Loader staysto the leftof Babel inloadersarray 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'] },

相关文章

react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...
react 本身提供了克隆组件的方法,但是平时开发中可能很少使...
mobx 是一个简单可扩展的状态管理库,中文官网链接。小编在接...
我们在平常的开发中不可避免的会有很多列表渲染逻辑,在 pc ...