Skip to content

Sharp Install

Sharp is a high-performance Node.js image processing library that supports various image formats and operations.

System Requirements

  • Node.js: Version 18.0.0 or higher
  • Platforms: Windows, macOS, Linux
  • Architecture: x64, ARM64

Installation Methods

Using npm

bash
npm install sharp

Using pnpm

bash
pnpm add sharp

Using yarn

bash
yarn add sharp

Pre-compiled Binaries

Sharp automatically downloads pre-compiled binaries suitable for your platform. If the installation download fails, you can choose to change the mirror site that contains the sharp and libvips binaries:

Configure Mirrors

bash
# Using Taobao mirror

#pnpm
pnpm config set sharp_binary_host "https://npmmirror.com/mirrors/sharp"
pnpm config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"

#npm
npm config set sharp_binary_host "https://npmmirror.com/mirrors/sharp"
npm config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"

# Or use GitHub mirror
npm config set sharp_binary_host "https://github.com/lovell/sharp/releases/download"

Manual Install Sharp

If automatic installation fails, you can manually install:

bash
# Clear cache
npm cache clean --force

# Reinstall
npm install sharp --ignore-scripts=false

Verify Installation

Create a test file to verify the installation:

javascript
// test-sharp.js
import sharp from 'sharp';

console.log('Sharp version:', sharp.versions.sharp);
console.log('libvips version:', sharp.versions.vips);

// Test basic functionality
sharp('test.jpg')
  .resize(100, 100)
  .toBuffer()
  .then(() => {
    console.log('Sharp installation successful!');
  })
  .catch((err) => {
    console.error('Sharp installation failed:', err);
  });

Troubleshooting

Installation Failures

If you encounter installation issues, try:

  1. Update Node.js: Ensure you're using the latest version
  2. Clear Cache: npm cache clean --force
  3. Delete node_modules: Delete and reinstall
  4. Check Network: Ensure you can access npm registry

Platform-Specific Issues

Windows

  • Ensure Visual Studio Build Tools is installed
  • If using WSL, ensure installation is done in the Linux environment

macOS

  • Ensure Xcode Command Line Tools is installed
  • If using M1/M2 chips, ensure ARM64 version is used

Linux

  • Install necessary development tools: sudo apt-get install build-essential
  • For Alpine Linux: apk add --no-cache vips-dev

Development Environment

TypeScript Support

Sharp includes complete TypeScript definitions:

bash
npm install --save-dev @types/node

Development Tools

Recommended tools for development:

  • VS Code: Excellent TypeScript support
  • ESLint: Code quality checking
  • Prettier: Code formatting

Next Steps

After installation, check out the Quick Start Guide to learn how to use Sharp.

Released under the Apache 2.0 License.