Sharp is a high-performance Node.js module designed for fast image processing, offering extensive support for resizing, converting, and manipulating JPEG, PNG, WebP, AVIF, GIF, TIFF, and SVG images. It leverages the native libvips library, making it one of the fastest solutions available for image operations in Node.js environments. The current stable version is 0.34.5, with frequent updates including patch releases and release candidates for upcoming major versions like 0.35.0. It's differentiated by its speed, low memory footprint, and broad format compatibility, making it suitable for high-volume image processing tasks such as thumbnail generation and on-the-fly image transformations for web applications. The project actively maintains support for recent Node.js LTS versions and ships with TypeScript types.
npm install sharpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use sharp to resize an image, convert it to different formats (WebP and JPEG), and apply common transformations like grayscale, saving the results to files. It also handles creating a dummy input file if needed.
Upgrade your Node.js environment to version 20.9.0 or higher. For production environments, consider moving to the latest LTS release of Node.js.
If you relied on `sharp` compiling from source during `npm install`, you will now need to explicitly run `npm run build` or `npm install --build-from-source` (pre-v0.34.5) if pre-built binaries are not suitable for your environment. Check the official documentation for the updated build process.
Review your code for usage of `failOnError`, `paletteBitDepth`, and the deprecated `sharpen` properties. Replace them with the recommended alternatives or remove them if no longer necessary. Consult the sharp changelog for specific replacements.
If installation fails, check the sharp installation guide for required system dependencies for your operating system. For `npm install --build-from-source` (deprecated in v0.34.5, replaced by `npm run build` in v0.35.0+), ensure you have `node-gyp` prerequisites installed (Python, C++ compiler).
For extremely large images, consider processing them in chunks or using input streams to manage memory more effectively. Ensure you are streaming or writing to file as soon as possible, rather than keeping large buffers in memory across multiple operations. Monitor Node.js heap usage and consider increasing `--max-old-space-size` if necessary, though optimizing code is preferable.
Ensure the directory where you are trying to write the image exists and that the Node.js process has write permissions for it. You might need to change directory permissions (e.g., `chmod 777 /path/to/output`) or run your application with appropriate user privileges.
Verify the input file's integrity and ensure its format is one of the supported types (JPEG, PNG, WebP, AVIF, GIF, TIFF, SVG, JP2). Check for common issues like incorrect file extensions that don't match the actual file content.
Run `npm install sharp` or `yarn add sharp`. If this persists, clear your npm cache (`npm cache clean --force`), delete `node_modules`, and `package-lock.json`, then reinstall. If it's a native module compilation issue, check system dependencies required for `libvips`.
This often points to a problem with the `sharp` installation's native components. Try completely reinstalling `sharp` by deleting `node_modules` and `package-lock.json` (or `yarn.lock`) and running `npm install sharp`. If installing on a custom environment or Docker, ensure all `libvips` dependencies are correctly set up for your specific build.
No dependency data recorded yet.