일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- MySQL
- 자바스크립트 알고리즘
- 맨해튼거리
- node.js
- 티스토리챌린지
- 프로그래머스 자바스크립트 풀이
- TypeScript
- 자료구조
- 좌표거리구하기
- 타입스크립트
- 깃허브
- 오블완
- Javascript 정렬
- 프로그래머스
- next.js
- 키패드누르기풀이
- Javascript sort
- js 알고리즘
- 정규표현식문제
- 프로그래머스 자바스크립트
- 정렬 알고리즘
- 자바스크립트 정렬
- 자바스크립트 배열
- 알고리즘
- 맨해튼거리예제
- TS
- binary search
- JavaScript
- mysql스키마
- 프로그래머스 신규아이디추천
- Today
- Total
FE PARADISE
[Next.js] Error: Invalid src prop on `next/image`hostname "..." is not configure 에러 해결하기 / next.config.js 이미지 도메인 설정 본문
[Next.js] Error: Invalid src prop on `next/image`hostname "..." is not configure 에러 해결하기 / next.config.js 이미지 도메인 설정
PARADISE247 2023. 5. 28. 01:05Error: Invalid src prop (https://images.unsplash.com/photo-1511920170033-f8396924c348?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=774&q=80) on `next/image`, hostname "images.unsplash.com" is not configured under images in your `next.config.js` See more info: https://nextjs.org/docs/messages/next-image-unconfigured-host
프로젝트 내부에 저장해 둔 사진이 아닌 외부 소스 사진을 가져오면 보게 되는 에러 메시지이다.
에러 메시지를 보면 'next.config.js'를 언급하고 있다. 그리하여 에러를 해결하기 위해 next.config.js를 수정해 줄 것이다.
👀 Next.js 12.3.0 이후 버전 사용 기준
next.config.js
// next.config.js
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'images.unsplash.com',
port: '',
pathname: '/*',
},
],
},
}
위와 같이 images : { remotePatterns: ...}} 내에서 사용하고자 하는 이미지의 src에 따라 protocol, hostname, port, pathname을 설정해주면 된다. 내가 사용하고자 하는 이미지의 주소는 "https://images.unsplash.com/photo-..." 이러하다. 그리하여 위와 같이 hostname : 'images.unsplash.com', pathname: '/*' 으로 설정해 주었다.
next.config.js 설정 후 이미지를 잘 불러오는 것을 확인할 수 있다.
👀 Next.js 12.3.0 이전 버전 사용 기준
next.config.js에 images: { domains: [...] } 내에 사용하고자 하는 외부 이미지 주소 domain을 추가하면 된다
// next.config.js
images: {
domains: ['images.unsplash.com'],
},
관련 공식 문서
next-image-unconfigured-host | Next.js
next/image Un-configured Host One of your pages that leverages the next/image component, passed a src value that uses a hostname in the URL that isn't defined in the images.remotePatterns in next.config.js. Add the protocol, hostname, port, and pathname to
nextjs.org
도움이 되셨다면 하트 한번만 눌러주세요 🩷
'프론트엔드 > Next.js' 카테고리의 다른 글
Next.js 페이지 성능 개선 - svg sprites 적용하기 (3) | 2024.03.22 |
---|---|
Next.js 사이트 성능 관리 - next/dynamic 사용하기 (2) | 2024.03.22 |
[Next.js] 웹사이트 버전 관리하기 - package.json version 설정& cookie에 버전 저장하기 ( + 버전 관리 규칙 semantic versioning ) (0) | 2024.02.21 |
[Next.js] Next.js13 App router에 styled-components 적용하기 / global style / registry.tsx (0) | 2023.07.11 |
[Next.js] CORS 에러 해결하기 (api 설정하기) (0) | 2023.05.04 |