While working on my Next.js application, I encountered an issue after installing/importing Plaiceholder for generating placeholder images. The error message I received is:
Module not found: Can't resolve 'child_process'
- Node version: 14.18.0
- Next.js version: 11.1.2
- Plaiceholder version: 2.2.0
- Sharp version: 0.29.2
Based on my understanding, this error indicates that webpack5 is attempting to bundle node packages that are not accessible to the client side. However, I have not made any customizations to the webpack configs and couldn't find any reference to this issue in the Plaiceholder documentation. How can I troubleshoot and fix this problem?
It's important to note that I aim to create the base64 data URL during the build process so it can be available as soon as the page loads, rather than fetched asynchronously at runtime.
Below is an excerpt from my next.config.js:
module.exports = {
reactStrictMode: true,
};
The package.json file only includes scripts
, dependencies
, and devDependencies
, with no modifications related to module resolution.
As a reference point, here is a simplified example using Plaiceholder:
import Image from "next/image";
import { getPlaiceholder } from "plaiceholder";
import React, { useState } from "react";
...
const { base64 } = await getPlaiceholder(imgUrl);
...
return (<Image
src={imgUrl}
placeholder="blur"
blurDataURL={base64}
/>);