When I try to add some image via webpack and react the image appears fine on the browser but I got the next warning:
WARNING in ./index.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <!DOCTYPE html>
| <html>
| <head>
@ . ^.*$
@ ./quiz.jsx
@ ./app.jsx
@ ./main.jsx
This is my react componet:
import * as React from 'react';
export const Quiz = (props) => {
const img = './images/williamshakespeare.jpg';
return (
<div className='row'>
<div className='col-md-4'>
<img src={require(`${img}`)} alt='author' />
</div>
</div>
);
}
And if I put the directly:
<img src={require(./images/williamshakespeare.jpg)} alt='author' />
the warning no appears.
Solved: Well, I don´t why but to avoid the WARNING I had to move the require from src to const img like:
export const Quiz = (props) => {
const img = require('./images/williamshakespeare.jpg');
return (
<div className='row'>
<div className='col-md-4'>
<img src={img} alt='author' />
</div>
</div>
);
}