当我安装react-icons并尝试导入
时 import FaBeer from 'react-icons/fa/beer';
我收到错误
Module parse failed: /Users/firfi/work/react-redux-todo/node_modules/react-icons/fa/beer.js Unexpected token (8:12)
如果我将导入更改为import FaBeer from 'react-icons/lib/fa/beer';
,我会
Module parse failed: /Users/firfi/work/react-redux-todo/node_modules/react-icon-base/index.js Unexpected token (3:50)
You may need an appropriate loader to handle this file type.
阅读错误消息,我发现我应该更改我的webpack配置。
所以我改变了
中的exlude声明{
test: /\.js$/, // Transform all .js files required somewhere with Babel
loader: 'babel',
exclude: /node_modules/,
query: options.babelQuery,
}
到exclude: /node_modules\/(?!(react-icon-base|react-icons)\/).*/,
现在我可以import FaBeer from 'react-icons/fa/beer';
但是,当我在渲染方法中使用它时,它会给我一个错误
warning.js:36Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of
{FaBeer {1}}
那么如何获得一些啤酒?