Images current show up like this.
Looking at the image source, it shows up as <img class="blur flex-shrink-0 mb-0 mr-3 rounded-full w-14 h-14 lazyloaded" alt="Profile" src="[object Object]">
Without using .default
as shown below, the src would be [object Module]
I am using next.js 12 (but the same issues happen on 11).
I am loading the images like this (Both the commented and uncommented result in the same):
<Image
className="flex-shrink-0 mb-0 mr-3 rounded-full w-14 h-14"
// src={require("../../../content/assets/profile.png").default}
// webpSrc={require("../../../content/assets/profile.png?webp").default}
// previewSrc={require("../../../content/assets/profile.png?lqip").default}
src={require("public/profile_new.png").default}
webpSrc={require("/public/profile_new.png?webp").default}
previewSrc={require("/public/profile_new.png?lqip").default}
alt="Profile"
/>
I've tried suggestions from: Webpack file-loader outputs [object Module] IMAGE: You may need an appropriate loader to handle this file type I can't reference an image in Next.js Nextjs: TypeError: unsupported file type: undefined after update to v.11
Below is my next.config.js. All the parts that have been commented out have at one point been uncommented but have yielded the same result.
const optimizedImages = require("next-optimized-images");
module.exports = optimizedImages({
webpack: (config, options) => {
config.module.rules.push({
test: /\.(png|jpe?g|gif)$/i,
use: [
options.defaultLoaders.babel,
{
loader: "file-loader",
options: {
esModule: false,
},
},
],
});
return config;
},
});
Here are my dependencies from package.json
"dependencies": {
"clsx": "^1.1.1",
"imagemin-mozjpeg": "^9.0.0",
"imagemin-optipng": "^8.0.0",
"lazysizes": "^5.3.1",
"lqip-loader": "^2.2.1",
"next": "^12.0.4",
"next-compose-plugins": "^2.2.1",
"next-optimized-images": "^2.6.2",
"next-themes": "^0.0.14",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-markdown": "^5.0.3",
"react-syntax-highlighter": "^15.4.3",
"react-toggle-dark-mode": "^1.0.3",
"remark-gfm": "^1.0.0",
"typeface-merriweather": "^1.1.13",
"typeface-open-sans": "^1.1.13",
"url-loader": "^4.1.1",
"webp-loader": "^0.6.0"
},
"devDependencies": {
"@babel/preset-env": "^7.16.4",
"@babel/preset-react": "^7.16.0",
"@tailwindcss/typography": "^0.4.0",
"autoprefixer": "^10.2.5",
"gray-matter": "^4.0.2",
"html-webpack-plugin": "^5.5.0",
"postcss": "^8.2.8",
"tailwindcss": "^2.0.4"
},
File structure: file structure