- React / Next.js
- Node.js / Koa.js
- Chart.js
- MySQL
- Jest
- Git
require
doesn't work with imageseg:
<img src={require("../public/images/serene.png")} />
isn't working even the Webpack has been well configured (esModule:false
withfile-loader
doesn't work), the images just don't show up on the page.
The error message is 404 (Not Found), and the Elements is<img src="[object Module]" >
on DevTools.
- My fix is to add
.default
at the end ofsrc
property , like '<img src={require("../public/images/serene.png").default} />`. It's a little weird, but it works.
- next-optimized-images plugin doesn't work
- This plugin must work with
require
orimport
when dealing with images require
must be statically analyzable, which means it cannot handle with variables- My workaround is to add
require
as a prefix in the database, so that the map loop can work well with variables.