Skip to content

설치 ​

Sharp는 다양한 이미지 형식과 작업을 지원하는 고성능 Node.js 이미지 처리 라이브러리입니다.

시스템 요구사항 ​

  • Node.js: 버전 18.0.0 이상
  • 플랫폼: Windows, macOS, Linux
  • 아키텍처: x64, ARM64

설치 방법 ​

npm 사용 ​

bash
npm install sharp

pnpm 사용 ​

bash
pnpm add sharp

yarn 사용 ​

bash
yarn add sharp

사전 컴파일된 바이너리 ​

Sharp는 자동으로 플랫폼에 맞는 사전 컴파일된 바이너리를 다운로드합니다. 설치 다운로드가 실패하는 경우 sharp 및 libvips 바이너리 파일을 포함하는 미러 사이트를 변경할 수 있습니다:

미러 소스 설정 ​

bash
# 타오바오 미러 사용

#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"

# 또는 GitHub 미러 사용
npm config set sharp_binary_host "https://github.com/lovell/sharp/releases/download"

수동 설치 ​

자동 설치가 실패하는 경우 수동으로 설치할 수 있습니다:

bash
# 캐시 지우기
npm cache clean --force

# 재설치
npm install sharp --ignore-scripts=false

설치 확인 ​

설치를 확인하기 위한 테스트 파일 생성:

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

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

// 기본 기능 테스트
sharp('test.jpg')
  .resize(100, 100)
  .toBuffer()
  .then(() => {
    console.log('Sharp 설치 성공!');
  })
  .catch((err) => {
    console.error('Sharp 설치 실패:', err);
  });

일반적인 문제 ​

설치 실패 ​

설치 문제가 발생하는 경우 다음을 시도하세요:

  1. Node.js 업데이트: 최신 버전 사용 확인
  2. 캐시 지우기: npm cache clean --force
  3. node_modules 삭제: 삭제 후 재설치
  4. 네트워크 확인: npm 저장소 접근 가능 여부 확인

플랫폼별 문제 ​

Windows ​

  • Visual Studio Build Tools 설치 확인
  • WSL 사용 시 Linux 환경에서 설치 확인

macOS ​

  • Xcode Command Line Tools 설치 확인
  • M1/M2 칩 사용 시 ARM64 버전 사용 확인

Linux ​

  • 필요한 개발 도구 설치: sudo apt-get install build-essential
  • Alpine Linux의 경우: apk add --no-cache vips-dev

개발 환경 ​

TypeScript 지원 ​

Sharp는 완전한 TypeScript 정의를 포함합니다:

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

개발 도구 ​

다음 도구를 사용하여 개발하는 것을 권장합니다:

  • VS Code: 우수한 TypeScript 지원
  • ESLint: 코드 품질 검사
  • Prettier: 코드 포맷팅

다음 단계 ​

설치가 완료되면 빠른 시작 가이드를 확인하여 Sharp 사용 방법을 알아보세요.

Apache 2.0 라이선스에 따라 릴리스되었습니다.