【发布时间】:2016-11-29 11:38:26
【问题描述】:
我看到 other question 关于 react-icons 没有加载到 webpack 中,但我得到的错误有点不同,我不知道如何修复它。
我正在尝试将 react-icons 与 webpack 一起使用,但出现以下错误:
./components/line-item.jsx 中的错误 未找到模块:错误:无法在 public/map/components @ ./components/line-item.jsx 7:18-40 中解析模块“react-icons”
这是我的 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'
}
]
}
};
这是我尝试在我的 line-item.jsx 中导入 react-icons 的地方
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 相关的不同错误
./~/react-icons/fa/beer.js 中的错误 模块解析失败:/Users/oyachinskiy/Documents/ichnaea-root/web-reporting/public/map/node_modules/react-icons/fa/beer.js 意外令牌 (8:12) 您可能需要适当的加载程序来处理此文件类型。
谢谢!
【问题讨论】:
标签: javascript reactjs webpack