【发布时间】:2017-12-30 17:50:34
【问题描述】:
我想在我正在使用 react 构建的网站上显示一张图片。下面是组件源代码:
import React, { Component } from 'react';
import style from './styles/AboutMeStyle.css';
export default class AboutMe extends Component{
render(){
return (
<div>
<img src={require ('./images/ProfilePic.jpg')}align="middle"/>
</div>
);
}
}
该文件似乎已找到,但我不断收到异常,指出模块解析失败...?这是来自终端的错误文本输出:
Module parse failed: /Users/megan/Desktop/Personal Website/client/components/images/ProfilePic.jpg
Unexpected character (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character (1:0)
...
我是不是写错了代码?还是我缺少一个模块?我已经安装了 image-webpack-loader 但它似乎没有做任何事情......这是我的 webpack.config.js :
module.exports = {
entry: './client/index.js',
output: {
path: __dirname + '/public/js',
filename: 'bundle.js'
},
devtool: 'source-map',
stats: {
colors: true,
reasons: true
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules)/,
loaders: ['babel']
},
{
test: /\.css$/,
loaders: ['style-loader', 'css-loader']
}
]
}
}
【问题讨论】:
-
请将图片替换为实际的错误信息。这将有助于使这个问题更易于搜索。
-
完成。将图片替换为文字
标签: javascript html node.js reactjs webpack