Skip to content

Commit f5365cc

Browse files
committed
Add err.sh for image config errors
1 parent 44fe971 commit f5365cc

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

errors/invalid-images-config.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Invalid images config
2+
3+
#### Why This Error Occurred
4+
5+
In your `next.config.js` file you provided an invalid config for the `images` field.
6+
7+
#### Possible Ways to Fix It
8+
9+
Make sure your `images` field follows the allowed config shape and values:
10+
11+
```js
12+
module.exports = {
13+
images: {
14+
// limit of 25 deviceSizes values
15+
deviceSizes: [320, 420, 768, 1024, 1200],
16+
// limit of 25 imageSizes values
17+
imageSizes: [],
18+
// limit of 50 domains values
19+
domains: [],
20+
path: '/_next/image',
21+
// can be 'default', 'imgix', 'cloudinary', or 'akamai'
22+
loader: 'default',
23+
},
24+
}
25+
```
26+
27+
### Useful Links
28+
29+
- [Image Optimization Documentation](https://nextjs.org/docs/basic-features/image-optimization)

packages/next/next-server/server/config.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,20 @@ function assignDefaults(userConfig: { [key: string]: any }) {
220220

221221
if (typeof images !== 'object') {
222222
throw new Error(
223-
`Specified images should be an object received ${typeof images}`
223+
`Specified images should be an object received ${typeof images}.\nSee more info here: https://err.sh/nextjs/invalid-images-config`
224224
)
225225
}
226226

227227
if (images.domains) {
228228
if (!Array.isArray(images.domains)) {
229229
throw new Error(
230-
`Specified images.domains should be an Array received ${typeof images.domains}`
230+
`Specified images.domains should be an Array received ${typeof images.domains}.\nSee more info here: https://err.sh/nextjs/invalid-images-config`
231231
)
232232
}
233233

234234
if (images.domains.length > 50) {
235235
throw new Error(
236-
`Specified images.domains exceeds length of 50, received length (${images.domains.length}), please reduce the length of the array to continue`
236+
`Specified images.domains exceeds length of 50, received length (${images.domains.length}), please reduce the length of the array to continue.\nSee more info here: https://err.sh/nextjs/invalid-images-config`
237237
)
238238
}
239239

@@ -244,21 +244,21 @@ function assignDefaults(userConfig: { [key: string]: any }) {
244244
throw new Error(
245245
`Specified images.domains should be an Array of strings received invalid values (${invalid.join(
246246
', '
247-
)})`
247+
)}).\nSee more info here: https://err.sh/nextjs/invalid-images-config`
248248
)
249249
}
250250
}
251251
if (images.deviceSizes) {
252252
const { deviceSizes } = images
253253
if (!Array.isArray(deviceSizes)) {
254254
throw new Error(
255-
`Specified images.deviceSizes should be an Array received ${typeof deviceSizes}`
255+
`Specified images.deviceSizes should be an Array received ${typeof deviceSizes}.\nSee more info here: https://err.sh/nextjs/invalid-images-config`
256256
)
257257
}
258258

259259
if (deviceSizes.length > 25) {
260260
throw new Error(
261-
`Specified images.deviceSizes exceeds length of 25, received length (${deviceSizes.length}), please reduce the length of the array to continue`
261+
`Specified images.deviceSizes exceeds length of 25, received length (${deviceSizes.length}), please reduce the length of the array to continue.\nSee more info here: https://err.sh/nextjs/invalid-images-config`
262262
)
263263
}
264264

@@ -270,21 +270,21 @@ function assignDefaults(userConfig: { [key: string]: any }) {
270270
throw new Error(
271271
`Specified images.deviceSizes should be an Array of numbers that are between 1 and 10000, received invalid values (${invalid.join(
272272
', '
273-
)})`
273+
)}).\nSee more info here: https://err.sh/nextjs/invalid-images-config`
274274
)
275275
}
276276
}
277277
if (images.imageSizes) {
278278
const { imageSizes } = images
279279
if (!Array.isArray(imageSizes)) {
280280
throw new Error(
281-
`Specified images.imageSizes should be an Array received ${typeof imageSizes}`
281+
`Specified images.imageSizes should be an Array received ${typeof imageSizes}.\nSee more info here: https://err.sh/nextjs/invalid-images-config`
282282
)
283283
}
284284

285285
if (imageSizes.length > 25) {
286286
throw new Error(
287-
`Specified images.imageSizes exceeds length of 25, received length (${imageSizes.length}), please reduce the length of the array to continue`
287+
`Specified images.imageSizes exceeds length of 25, received length (${imageSizes.length}), please reduce the length of the array to continue.\nSee more info here: https://err.sh/nextjs/invalid-images-config`
288288
)
289289
}
290290

@@ -296,7 +296,7 @@ function assignDefaults(userConfig: { [key: string]: any }) {
296296
throw new Error(
297297
`Specified images.imageSizes should be an Array of numbers that are between 1 and 10000, received invalid values (${invalid.join(
298298
', '
299-
)})`
299+
)}).\nSee more info here: https://err.sh/nextjs/invalid-images-config`
300300
)
301301
}
302302
}

0 commit comments

Comments
 (0)