Skip to content

Commit c4e1f61

Browse files
icyJosephmolebox
andauthored
docs: Verbose troubleshooting for unconfigured hosts (#84271)
Closes: https://linear.app/vercel/issue/DOC-5151/unconfigured-image-host --------- Co-authored-by: Rich Haines <[email protected]>
1 parent 0014161 commit c4e1f61

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

errors/next-image-unconfigured-host.mdx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ title: '`next/image` Un-configured Host'
66

77
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`.
88

9+
Each part of the `src` value is strictly matched against your `images.remotePatterns` definitions. Matching is exact and case-sensitive, meaning a mismatch in any single part will fail the check.
10+
11+
For a URL like `https://example.org/images/example?v=1234`, the following parts must match the pattern you configured:
12+
13+
- **Protocol**: `http` vs `https` must match exactly.
14+
- **Hostname**: `example.org` is different from `www.example.org` and from subdomains like `assets.example.org`.
15+
- **Port**: If present (e.g. `:3000`), it must be included.
16+
- **Pathname**: The path must be covered by your glob, e.g. `/**` or `/images/**`.
17+
- **Search**: If specified in a pattern, it must match the full search string exactly (including the leading `?`). Globs are not supported for search.
18+
19+
If any of these differ from the actual `src`, the image will be rejected.
20+
21+
Common pitfalls that cause this error:
22+
23+
- Using `https` in `src` but only allowing `http` (or vice‑versa).
24+
- Loading from a subdomain like `assets.example.com` while only configuring `example.com`.
25+
- Missing a port during local/dev usage, e.g. `http://localhost:3000`.
26+
- A too‑narrow pathname pattern (e.g. `/images/` instead of `/images/**`).
27+
- When using the `URL` constructor, if no `search` is specified, then the `search` property is set to an empty string `''`, which means search params are **NOT** allowed.
28+
29+
See the [Remote Patterns](/docs/pages/api-reference/components/image#remotepatterns) reference for details.
30+
931
## Possible Ways to Fix It
1032

1133
Add the protocol, hostname, port, and pathname to the `images.remotePatterns` config in `next.config.js`:
@@ -18,6 +40,39 @@ module.exports = {
1840
}
1941
```
2042

43+
### With specific search params
44+
45+
To allow a single search param, `v=1234`:
46+
47+
```js filename="next.config.js"
48+
module.exports = {
49+
images: {
50+
remotePatterns: [
51+
new URL('https://assets.example.com/account123/**?v=1234'),
52+
],
53+
},
54+
}
55+
```
56+
57+
### Any search params
58+
59+
To allow any search parameter, use the remote pattern object, omitting the `search` key.
60+
61+
```js filename="next.config.js"
62+
module.exports = {
63+
images: {
64+
remotePatterns: [
65+
{
66+
protocol: 'https',
67+
hostname: 'assets.example.com',
68+
port: '',
69+
pathname: '/account123/**',
70+
},
71+
],
72+
},
73+
}
74+
```
75+
2176
### Fixing older versions of Next.js
2277

2378
<details>

0 commit comments

Comments
 (0)