Skip to content

Commit 27f56eb

Browse files
ijjkstyfle
andauthored
Add err.sh for missing images domain (#18325)
* Add err.sh for missing images domain * Apply suggestions from code review Co-authored-by: Steven <[email protected]> * Update test Co-authored-by: Steven <[email protected]>
1 parent 6d4395f commit 27f56eb

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# next/image Un-configured Host
2+
3+
#### Why This Error Occurred
4+
5+
On one of your pages that leverages the `next/image` component, you passed a `src` value that uses a `hostname` in the URL that isn't defined in the `images` config in `next.config.js`.
6+
7+
#### Possible Ways to Fix It
8+
9+
Add the `hostname` to your `images` config in `next.config.js`:
10+
11+
```js
12+
// next.config.js
13+
module.exports = {
14+
images: {
15+
domains: ['assets.example.com'],
16+
},
17+
}
18+
```
19+
20+
### Useful Links
21+
22+
- [Image Optimization Documetnation](https://nextjs.org/docs/basic-features/image-optimization)

packages/next/client/image.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,14 @@ function defaultLoader({ root, src, width, quality }: LoaderProps): string {
431431
} catch (err) {
432432
console.error(err)
433433
throw new Error(
434-
`Failed to parse "${src}" if using relative image it must start with a leading slash "/" or be an absolute URL`
434+
`Failed to parse "${src}" in "next/image", if using relative image it must start with a leading slash "/" or be an absolute URL (http:// or https://)`
435435
)
436436
}
437437

438438
if (!configDomains.includes(parsedSrc.hostname)) {
439439
throw new Error(
440-
`Invalid src prop (${src}) on \`next/image\`, hostname is not configured under images in your \`next.config.js\``
440+
`Invalid src prop (${src}) on \`next/image\`, hostname "${parsedSrc.hostname}" is not configured under images in your \`next.config.js\`\n` +
441+
`See more info: https://err.sh/nextjs/next-image-unconfigured-host`
441442
)
442443
}
443444
}

test/integration/image-component/default/test/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function runTests(mode) {
117117

118118
await hasRedbox(browser)
119119
expect(await getRedboxHeader(browser)).toContain(
120-
'Invalid src prop (https://google.com/test.png) on `next/image`, hostname is not configured under images in your `next.config.js`'
120+
'Invalid src prop (https://google.com/test.png) on `next/image`, hostname "google.com" is not configured under images in your `next.config.js`'
121121
)
122122
})
123123
}

0 commit comments

Comments
 (0)