我看到了other question约react-icons不加载在webpack中,但我得到的错误有点不同,我不知道如何解决它。react-icons解决与webpack错误
我试图用反应-的图标,但的WebPack我发现了以下错误:
ERROR in ./components/line-item.jsx Module not found: Error: Cannot resolve module 'react-icons' in public/map/components @ ./components/line-item.jsx 7:18-40
这里是我的WebPack设置:
var path = require('path');
var webpack = require('webpack');
var config = {
iconPath: 'node_modules/react-icons'
};
module.exports = {
entry: './main.js',
output: {path: __dirname, filename: 'bundle.js'},
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react']
}
},
{
test: /react-icons\/(.)*(.js)$/,
loader: 'babel',
include: config.iconPath
},
{
test: /\.scss/,
loader: 'style!css!sass'
}
]
}
};
这里就是我试图导入我的行中的react-icons -jsx
import React from 'react';
import FaBeer from 'react-icons';
var LineItem = React.createClass({
})
module.exports = LineItem;
我是全新的webpack,只是学习,因为我要去埠任何帮助将不胜感激。
编辑: 我改变了进口
import FaBeer from 'react-icons/fa/beer';
,现在得到一个不同的错误,我做的认为这是相关的WebPack
ERROR in ./~/react-icons/fa/beer.js Module parse failed: /Users/oyachinskiy/Documents/ichnaea-root/web-reporting/public/map/node_modules/react-icons/fa/beer.js Unexpected token (8:12) You may need an appropriate loader to handle this file type.
谢谢!
我反应过来,图标安装作为一个依赖关系,而这也不起作用。当我只是试图要求它时发生同样的错误。 – yoleg
看到我编辑的答案 - 你的语法与他们的文档不匹配。 – Toby
好吧,我得到一个不同的错误...错误在./~/react-icons/fa/beer.js 模块解析失败的网络报告/公共/地图/ node_modules/react-icons/fa /啤酒。 js意外标记(8:12) 您可能需要一个合适的加载器来处理此文件类型。这就是为什么我认为我需要编辑webpack配置 – yoleg