-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
errors-data.ts
1511 lines (1474 loc) · 66.1 KB
/
errors-data.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// BEFORE ADDING AN ERROR: Please look at the README.md in this folder for general guidelines on writing error messages
// Additionally, this code, much like `@types/astro.ts`, is used to generate documentation, so make sure to pass
// your changes by our wonderful docs team before merging!
import type { ZodError } from 'zod';
export interface ErrorData {
name: string;
title: string;
message?: string | ((...params: any) => string);
hint?: string | ((...params: any) => string);
}
/**
* @docs
* @kind heading
* @name Astro Errors
*/
// Astro Errors, most errors will go here!
/**
* @docs
* @message
* Unknown compiler error.
* @see
* - [withastro/compiler issues list](https://astro.build/issues/compiler)
* @description
* Astro encountered an unknown error while compiling your files. In most cases, this is not your fault, but an issue in our compiler.
*
* If there isn't one already, please [create an issue](https://astro.build/issues/compiler).
*/
export const UnknownCompilerError = {
name: 'UnknownCompilerError',
title: 'Unknown compiler error.',
hint: 'This is almost always a problem with the Astro compiler, not your code. Please open an issue at https://astro.build/issues/compiler.',
} satisfies ErrorData;
// 1xxx and 2xxx codes are reserved for compiler errors and warnings respectively
/**
* @docs
* @see
* - [Enabling SSR in Your Project](https://docs.astro.build/en/guides/server-side-rendering/)
* - [Astro.redirect](https://docs.astro.build/en/reference/api-reference/#astroredirect)
* @description
* The `Astro.redirect` function is only available when [Server-side rendering](/en/guides/server-side-rendering/) is enabled.
*
* To redirect on a static website, the [meta refresh attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta) can be used. Certain hosts also provide config-based redirects (ex: [Netlify redirects](https://docs.netlify.com/routing/redirects/)).
* @deprecated Deprecated since version 2.6.
*/
export const StaticRedirectNotAvailable = {
name: 'StaticRedirectNotAvailable',
title: '`Astro.redirect` is not available in static mode.',
message:
"Redirects are only available when using `output: 'server'` or `output: 'hybrid'`. Update your Astro config if you need SSR features.",
hint: 'See https://docs.astro.build/en/guides/server-side-rendering/ for more information on how to enable SSR.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Official integrations](https://docs.astro.build/en/guides/integrations-guide/#official-integrations)
* - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#astroclientaddress)
* @description
* The adapter you're using unfortunately does not support `Astro.clientAddress`.
*/
export const ClientAddressNotAvailable = {
name: 'ClientAddressNotAvailable',
title: '`Astro.clientAddress` is not available in current adapter.',
message: (adapterName: string) =>
`\`Astro.clientAddress\` is not available in the \`${adapterName}\` adapter. File an issue with the adapter to add support.`,
} satisfies ErrorData;
/**
* @docs
* @see
* - [Enabling SSR in Your Project](https://docs.astro.build/en/guides/server-side-rendering/)
* - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#astroclientaddress)
* @description
* The `Astro.clientAddress` property is only available when [Server-side rendering](https://docs.astro.build/en/guides/server-side-rendering/) is enabled.
*
* To get the user's IP address in static mode, different APIs such as [Ipify](https://www.ipify.org/) can be used in a [Client-side script](https://docs.astro.build/en/guides/client-side-scripts/) or it may be possible to get the user's IP using a serverless function hosted on your hosting provider.
*/
export const StaticClientAddressNotAvailable = {
name: 'StaticClientAddressNotAvailable',
title: '`Astro.clientAddress` is not available in static mode.',
message:
"`Astro.clientAddress` is only available when using `output: 'server'` or `output: 'hybrid'`. Update your Astro config if you need SSR features.",
hint: 'See https://docs.astro.build/en/guides/server-side-rendering/ for more information on how to enable SSR.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [getStaticPaths()](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
* @description
* A [dynamic route](https://docs.astro.build/en/guides/routing/#dynamic-routes) was matched, but no corresponding path was found for the requested parameters. This is often caused by a typo in either the generated or the requested path.
*/
export const NoMatchingStaticPathFound = {
name: 'NoMatchingStaticPathFound',
title: 'No static path found for requested path.',
message: (pathName: string) =>
`A \`getStaticPaths()\` route pattern was matched, but no matching static path was found for requested path \`${pathName}\`.`,
hint: (possibleRoutes: string[]) =>
`Possible dynamic routes being matched: ${possibleRoutes.join(', ')}.`,
} satisfies ErrorData;
/**
* @docs
* @message Route returned a `RETURNED_VALUE`. Only a Response can be returned from Astro files.
* @see
* - [Response](https://docs.astro.build/en/guides/server-side-rendering/#response)
* @description
* Only instances of [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) can be returned inside Astro files.
* ```astro title="pages/login.astro"
* ---
* return new Response(null, {
* status: 404,
* statusText: 'Not found'
* });
*
* // Alternatively, for redirects, Astro.redirect also returns an instance of Response
* return Astro.redirect('/login');
* ---
* ```
*
*/
export const OnlyResponseCanBeReturned = {
name: 'OnlyResponseCanBeReturned',
title: 'Invalid type returned by Astro page.',
message: (route: string | undefined, returnedValue: string) =>
`Route \`${
route ? route : ''
}\` returned a \`${returnedValue}\`. Only a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) can be returned from Astro files.`,
hint: 'See https://docs.astro.build/en/guides/server-side-rendering/#response for more information.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [`client:media`](https://docs.astro.build/en/reference/directives-reference/#clientmedia)
* @description
* A [media query](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries) parameter is required when using the `client:media` directive.
*
* ```astro
* <Counter client:media="(max-width: 640px)" />
* ```
*/
export const MissingMediaQueryDirective = {
name: 'MissingMediaQueryDirective',
title: 'Missing value for `client:media` directive.',
message:
'Media query not provided for `client:media` directive. A media query similar to `client:media="(max-width: 600px)"` must be provided',
} satisfies ErrorData;
/**
* @docs
* @message Unable to render `COMPONENT_NAME`. There are `RENDERER_COUNT` renderer(s) configured in your `astro.config.mjs` file, but none were able to server-side render `COMPONENT_NAME`.
* @see
* - [Frameworks components](https://docs.astro.build/en/guides/framework-components/)
* - [UI Frameworks](https://docs.astro.build/en/guides/integrations-guide/#official-integrations)
* @description
* None of the installed integrations were able to render the component you imported. Make sure to install the appropriate integration for the type of component you are trying to include in your page.
*
* For JSX / TSX files, [@astrojs/react](https://docs.astro.build/en/guides/integrations-guide/react/), [@astrojs/preact](https://docs.astro.build/en/guides/integrations-guide/preact/) or [@astrojs/solid-js](https://docs.astro.build/en/guides/integrations-guide/solid-js/) can be used. For Vue and Svelte files, the [@astrojs/vue](https://docs.astro.build/en/guides/integrations-guide/vue/) and [@astrojs/svelte](https://docs.astro.build/en/guides/integrations-guide/svelte/) integrations can be used respectively
*/
export const NoMatchingRenderer = {
name: 'NoMatchingRenderer',
title: 'No matching renderer found.',
message: (
componentName: string,
componentExtension: string | undefined,
plural: boolean,
validRenderersCount: number
) =>
`Unable to render \`${componentName}\`.
${
validRenderersCount > 0
? `There ${plural ? 'are' : 'is'} ${validRenderersCount} renderer${plural ? 's' : ''} configured in your \`astro.config.mjs\` file,
but ${plural ? 'none were' : 'it was not'} able to server-side render \`${componentName}\`.`
: `No valid renderer was found ${
componentExtension
? `for the \`.${componentExtension}\` file extension.`
: `for this file extension.`
}`
}`,
hint: (probableRenderers: string) =>
`Did you mean to enable the ${probableRenderers} integration?\n\nSee https://docs.astro.build/en/guides/framework-components/ for more information on how to install and configure integrations.`,
} satisfies ErrorData;
/**
* @docs
* @see
* - [addRenderer option](https://docs.astro.build/en/reference/integrations-reference/#addrenderer-option)
* - [Hydrating framework components](https://docs.astro.build/en/guides/framework-components/#hydrating-interactive-components)
* @description
* Astro tried to hydrate a component on the client, but the renderer used does not provide a client entrypoint to use to hydrate.
*
*/
export const NoClientEntrypoint = {
name: 'NoClientEntrypoint',
title: 'No client entrypoint specified in renderer.',
message: (componentName: string, clientDirective: string, rendererName: string) =>
`\`${componentName}\` component has a \`client:${clientDirective}\` directive, but no client entrypoint was provided by \`${rendererName}\`.`,
hint: 'See https://docs.astro.build/en/reference/integrations-reference/#addrenderer-option for more information on how to configure your renderer.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [`client:only`](https://docs.astro.build/en/reference/directives-reference/#clientonly)
* @description
*
* `client:only` components are not run on the server, as such Astro does not know (and cannot guess) which renderer to use and require a hint. Like such:
*
* ```astro
* <SomeReactComponent client:only="react" />
* ```
*/
export const NoClientOnlyHint = {
name: 'NoClientOnlyHint',
title: 'Missing hint on client:only directive.',
message: (componentName: string) =>
`Unable to render \`${componentName}\`. When using the \`client:only\` hydration strategy, Astro needs a hint to use the correct renderer.`,
hint: (probableRenderers: string) =>
`Did you mean to pass \`client:only="${probableRenderers}"\`? See https://docs.astro.build/en/reference/directives-reference/#clientonly for more information on client:only`,
} satisfies ErrorData;
/**
* @docs
* @see
* - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
* - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
* @description
* The `params` property in `getStaticPaths`'s return value (an array of objects) should also be an object.
*
* ```astro title="pages/blog/[id].astro"
* ---
* export async function getStaticPaths() {
* return [
* { params: { slug: "blog" } },
* { params: { slug: "about" } }
* ];
*}
*---
* ```
*/
export const InvalidGetStaticPathParam = {
name: 'InvalidGetStaticPathParam',
title: 'Invalid value returned by a `getStaticPaths` path.',
message: (paramType) =>
`Invalid params given to \`getStaticPaths\` path. Expected an \`object\`, got \`${paramType}\``,
hint: 'See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
* @description
* `getStaticPaths`'s return value must be an array of objects. In most cases, this error happens because an array of array was returned. Using [`.flatMap()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) or a [`.flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) call may be useful.
*
* ```ts title="pages/blog/[id].astro"
* export async function getStaticPaths() {
* return [ // <-- Array
* { params: { slug: "blog" } }, // <-- Object
* { params: { slug: "about" } }
* ];
*}
* ```
*/
export const InvalidGetStaticPathsEntry = {
name: 'InvalidGetStaticPathsEntry',
title: "Invalid entry inside getStaticPath's return value",
message: (entryType) =>
`Invalid entry returned by getStaticPaths. Expected an object, got \`${entryType}\``,
hint: "If you're using a `.map` call, you might be looking for `.flatMap()` instead. See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.",
} satisfies ErrorData;
/**
* @docs
* @see
* - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
* - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
* @description
* `getStaticPaths`'s return value must be an array of objects.
*
* ```ts title="pages/blog/[id].astro"
* export async function getStaticPaths() {
* return [ // <-- Array
* { params: { slug: "blog" } },
* { params: { slug: "about" } }
* ];
*}
* ```
*/
export const InvalidGetStaticPathsReturn = {
name: 'InvalidGetStaticPathsReturn',
title: 'Invalid value returned by getStaticPaths.',
message: (returnType) =>
`Invalid type returned by \`getStaticPaths\`. Expected an \`array\`, got \`${returnType}\``,
hint: 'See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.',
} satisfies ErrorData;
/**
* @docs
* @deprecated Deprecated since Astro 4.0. The RSS helper no longer exists with an error fallback.
* @see
* - [RSS Guide](https://docs.astro.build/en/guides/rss/)
* @description
* `getStaticPaths` no longer expose an helper for generating a RSS feed. We recommend migrating to the [@astrojs/rss](https://docs.astro.build/en/guides/rss/#setting-up-astrojsrss)integration instead.
*/
export const GetStaticPathsRemovedRSSHelper = {
name: 'GetStaticPathsRemovedRSSHelper',
title: 'getStaticPaths RSS helper is not available anymore.',
message:
'The RSS helper has been removed from `getStaticPaths`. Try the new @astrojs/rss package instead.',
hint: 'See https://docs.astro.build/en/guides/rss/ for more information.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
* - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
* @description
* Every route specified by `getStaticPaths` require a `params` property specifying the path parameters needed to match the route.
*
* For instance, the following code:
* ```astro title="pages/blog/[id].astro"
* ---
* export async function getStaticPaths() {
* return [
* { params: { id: '1' } }
* ];
* }
* ---
* ```
* Will create the following route: `site.com/blog/1`.
*/
export const GetStaticPathsExpectedParams = {
name: 'GetStaticPathsExpectedParams',
title: 'Missing params property on `getStaticPaths` route.',
message: 'Missing or empty required `params` property on `getStaticPaths` route.',
hint: 'See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
* - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
* @description
* Since `params` are encoded into the URL, only certain types are supported as values.
*
* ```astro title="/route/[id].astro"
* ---
* export async function getStaticPaths() {
* return [
* { params: { id: '1' } } // Works
* { params: { id: 2 } } // Works
* { params: { id: false } } // Does not work
* ];
* }
* ---
* ```
*
* In routes using [rest parameters](https://docs.astro.build/en/guides/routing/#rest-parameters), `undefined` can be used to represent a path with no parameters passed in the URL:
*
* ```astro title="/route/[...id].astro"
* ---
* export async function getStaticPaths() {
* return [
* { params: { id: 1 } } // /route/1
* { params: { id: 2 } } // /route/2
* { params: { id: undefined } } // /route/
* ];
* }
* ---
* ```
*/
export const GetStaticPathsInvalidRouteParam = {
name: 'GetStaticPathsInvalidRouteParam',
title: 'Invalid value for `getStaticPaths` route parameter.',
message: (key: string, value: any, valueType: any) =>
`Invalid getStaticPaths route parameter for \`${key}\`. Expected undefined, a string or a number, received \`${valueType}\` (\`${value}\`)`,
hint: 'See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Dynamic Routes](https://docs.astro.build/en/guides/routing/#dynamic-routes)
* - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
* - [Server-side Rendering](https://docs.astro.build/en/guides/server-side-rendering/)
* @description
* In [Static Mode](https://docs.astro.build/en/guides/routing/#static-ssg-mode), all routes must be determined at build time. As such, dynamic routes must `export` a `getStaticPaths` function returning the different paths to generate.
*/
export const GetStaticPathsRequired = {
name: 'GetStaticPathsRequired',
title: '`getStaticPaths()` function required for dynamic routes.',
message:
'`getStaticPaths()` function is required for dynamic routes. Make sure that you `export` a `getStaticPaths` function from your dynamic route.',
hint: `See https://docs.astro.build/en/guides/routing/#dynamic-routes for more information on dynamic routes.
Alternatively, set \`output: "server"\` or \`output: "hybrid"\` in your Astro config file to switch to a non-static server build. This error can also occur if using \`export const prerender = true;\`.
See https://docs.astro.build/en/guides/server-side-rendering/ for more information on non-static rendering.`,
} satisfies ErrorData;
/**
* @docs
* @see
* - [Named slots](https://docs.astro.build/en/basics/astro-components/#named-slots)
* @description
* Certain words cannot be used for slot names due to being already used internally.
*/
export const ReservedSlotName = {
name: 'ReservedSlotName',
title: 'Invalid slot name.',
message: (slotName: string) =>
`Unable to create a slot named \`${slotName}\`. \`${slotName}\` is a reserved slot name. Please update the name of this slot.`,
} satisfies ErrorData;
/**
* @docs
* @see
* - [Server-side Rendering](https://docs.astro.build/en/guides/server-side-rendering/)
* @description
* To use server-side rendering, an adapter needs to be installed so Astro knows how to generate the proper output for your targeted deployment platform.
*/
export const NoAdapterInstalled = {
name: 'NoAdapterInstalled',
title: 'Cannot use Server-side Rendering without an adapter.',
message: `Cannot use \`output: 'server'\` or \`output: 'hybrid'\` without an adapter. Please install and configure the appropriate server adapter for your final deployment.`,
hint: 'See https://docs.astro.build/en/guides/server-side-rendering/ for more information.',
} satisfies ErrorData;
/**
* @docs
* @description
* No import statement was found for one of the components. If there is an import statement, make sure you are using the same identifier in both the imports and the component usage.
*/
export const NoMatchingImport = {
name: 'NoMatchingImport',
title: 'No import found for component.',
message: (componentName: string) =>
`Could not render \`${componentName}\`. No matching import has been found for \`${componentName}\`.`,
hint: 'Please make sure the component is properly imported.',
} satisfies ErrorData;
/**
* @docs
* @message
* **Example error messages:**<br/>
* InvalidPrerenderExport: A `prerender` export has been detected, but its value cannot be statically analyzed.
* @description
* The `prerender` feature only supports a subset of valid JavaScript — be sure to use exactly `export const prerender = true` so that our compiler can detect this directive at build time. Variables, `let`, and `var` declarations are not supported.
*/
export const InvalidPrerenderExport = {
name: 'InvalidPrerenderExport',
title: 'Invalid prerender export.',
message(prefix: string, suffix: string, isHydridOuput: boolean) {
const defaultExpectedValue = isHydridOuput ? 'false' : 'true';
let msg = `A \`prerender\` export has been detected, but its value cannot be statically analyzed.`;
if (prefix !== 'const') msg += `\nExpected \`const\` declaration but got \`${prefix}\`.`;
if (suffix !== 'true')
msg += `\nExpected \`${defaultExpectedValue}\` value but got \`${suffix}\`.`;
return msg;
},
hint: 'Mutable values declared at runtime are not supported. Please make sure to use exactly `export const prerender = true`.',
} satisfies ErrorData;
/**
* @docs
* @message
* **Example error messages:**<br/>
* InvalidComponentArgs: Invalid arguments passed to `<MyAstroComponent>` component.
* @description
* Astro components cannot be rendered manually via a function call, such as `Component()` or `{items.map(Component)}`. Prefer the component syntax `<Component />` or `{items.map(item => <Component {...item} />)}`.
*/
export const InvalidComponentArgs = {
name: 'InvalidComponentArgs',
title: 'Invalid component arguments.',
message: (name: string) => `Invalid arguments passed to${name ? ` <${name}>` : ''} component.`,
hint: 'Astro components cannot be rendered directly via function call, such as `Component()` or `{items.map(Component)}`.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Pagination](https://docs.astro.build/en/guides/routing/#pagination)
* @description
* The page number parameter was not found in your filepath.
*/
export const PageNumberParamNotFound = {
name: 'PageNumberParamNotFound',
title: 'Page number param not found.',
message: (paramName: string) =>
`[paginate()] page number param \`${paramName}\` not found in your filepath.`,
hint: 'Rename your file to `[page].astro` or `[...page].astro`.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* - [Image component](https://docs.astro.build/en/guides/images/#image--astroassets)
* - [Image component#alt](https://docs.astro.build/en/guides/images/#alt-required)
* @description
* The `alt` property allows you to provide descriptive alt text to users of screen readers and other assistive technologies. In order to ensure your images are accessible, the `Image` component requires that an `alt` be specified.
*
* If the image is merely decorative (i.e. doesn’t contribute to the understanding of the page), set `alt=""` so that screen readers know to ignore the image.
*/
export const ImageMissingAlt = {
name: 'ImageMissingAlt',
title: 'Image missing required "alt" property.',
message:
'Image missing "alt" property. "alt" text is required to describe important images on the page.',
hint: 'Use an empty string ("") for decorative images.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Image Service API](https://docs.astro.build/en/reference/image-service-reference/)
* @description
* There was an error while loading the configured image service. This can be caused by various factors, such as your image service not properly exporting a compatible object in its default export, or an incorrect path.
*
* If you believe that your service is properly configured and this error is wrong, please [open an issue](https://astro.build/issues/).
*/
export const InvalidImageService = {
name: 'InvalidImageService',
title: 'Error while loading image service.',
message:
'There was an error loading the configured image service. Please see the stack trace for more information.',
} satisfies ErrorData;
/**
* @docs
* @message
* Missing width and height attributes for `IMAGE_URL`. When using remote images, both dimensions are required in order to avoid cumulative layout shift (CLS).
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* - [Image component#width-and-height-required](https://docs.astro.build/en/guides/images/#width-and-height-required-for-images-in-public)
* @description
* For remote images, `width` and `height` cannot automatically be inferred from the original file. To avoid cumulative layout shift (CLS), either specify these two properties, or set [`inferSize`](https://docs.astro.build/en/guides/images/#infersize) to `true` to fetch a remote image's original dimensions.
*
* If your image is inside your `src` folder, you probably meant to import it instead. See [the Imports guide for more information](https://docs.astro.build/en/guides/imports/#other-assets).
*/
export const MissingImageDimension = {
name: 'MissingImageDimension',
title: 'Missing image dimensions',
message: (missingDimension: 'width' | 'height' | 'both', imageURL: string) =>
`Missing ${
missingDimension === 'both' ? 'width and height attributes' : `${missingDimension} attribute`
} for ${imageURL}. When using remote images, both dimensions are required unless in order to avoid CLS.`,
hint: 'If your image is inside your `src` folder, you probably meant to import it instead. See [the Imports guide for more information](https://docs.astro.build/en/guides/imports/#other-assets). You can also use `inferSize={true}` for remote images to get the original dimensions.',
} satisfies ErrorData;
/**
* @docs
* @message
* Failed to get the dimensions for `IMAGE_URL`.
* @description
* Determining the remote image's dimensions failed. This is typically caused by an incorrect URL or attempting to infer the size of an image in the public folder which is not possible.
*/
export const FailedToFetchRemoteImageDimensions = {
name: 'FailedToFetchRemoteImageDimensions',
title: 'Failed to retrieve remote image dimensions',
message: (imageURL: string) => `Failed to get the dimensions for ${imageURL}.`,
hint: 'Verify your remote image URL is accurate, and that you are not using `inferSize` with a file located in your `public/` folder.',
} satisfies ErrorData;
/**
* @docs
* @description
* The built-in image services do not currently support optimizing all image formats.
*
* For unsupported formats such as GIFs, you may be able to use an `img` tag directly:
* ```astro
* ---
* import rocket from '../assets/images/rocket.gif';
* ---
*
* <img src={rocket.src} width={rocket.width} height={rocket.height} alt="A rocketship in space." />
* ```
*/
export const UnsupportedImageFormat = {
name: 'UnsupportedImageFormat',
title: 'Unsupported image format',
message: (format: string, imagePath: string, supportedFormats: readonly string[]) =>
`Received unsupported format \`${format}\` from \`${imagePath}\`. Currently only ${supportedFormats.join(
', '
)} are supported by our image services.`,
hint: "Using an `img` tag directly instead of the `Image` component might be what you're looking for.",
} satisfies ErrorData;
/**
* @docs
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* @description
* Astro does not currently supporting converting between vector (such as SVGs) and raster (such as PNGs and JPEGs) images.
*/
export const UnsupportedImageConversion = {
name: 'UnsupportedImageConversion',
title: 'Unsupported image conversion',
message:
'Converting between vector (such as SVGs) and raster (such as PNGs and JPEGs) images is not currently supported.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
* - [`params`](https://docs.astro.build/en/reference/api-reference/#params)
* @description
* The endpoint is prerendered with an `undefined` param so the generated path will collide with another route.
*
* If you cannot prevent passing `undefined`, then an additional extension can be added to the endpoint file name to generate the file with a different name. For example, renaming `pages/api/[slug].ts` to `pages/api/[slug].json.ts`.
*/
export const PrerenderDynamicEndpointPathCollide = {
name: 'PrerenderDynamicEndpointPathCollide',
title: 'Prerendered dynamic endpoint has path collision.',
message: (pathname: string) =>
`Could not render \`${pathname}\` with an \`undefined\` param as the generated path will collide during prerendering. Prevent passing \`undefined\` as \`params\` for the endpoint's \`getStaticPaths()\` function, or add an additional extension to the endpoint's filename.`,
hint: (filename: string) =>
`Rename \`${filename}\` to \`${filename.replace(/\.(?:js|ts)/, (m) => `.json` + m)}\``,
} satisfies ErrorData;
/**
* @docs
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* @description
* An image's `src` property is not valid. The Image component requires the `src` attribute to be either an image that has been ESM imported or a string. This is also true for the first parameter of `getImage()`.
*
* ```astro
* ---
* import { Image } from "astro:assets";
* import myImage from "../assets/my_image.png";
* ---
*
* <Image src={myImage} alt="..." />
* <Image src="https://example.com/logo.png" width={300} height={300} alt="..." />
* ```
*
* In most cases, this error happens when the value passed to `src` is undefined.
*/
export const ExpectedImage = {
name: 'ExpectedImage',
title: 'Expected src to be an image.',
message: (src: string, typeofOptions: string, fullOptions: string) =>
`Expected \`src\` property for \`getImage\` or \`<Image />\` to be either an ESM imported image or a string with the path of a remote image. Received \`${src}\` (type: \`${typeofOptions}\`).\n\nFull serialized options received: \`${fullOptions}\`.`,
hint: "This error can often happen because of a wrong path. Make sure the path to your image is correct. If you're passing an async function, make sure to call and await it.",
} satisfies ErrorData;
/**
* @docs
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* @description
* `getImage()`'s first parameter should be an object with the different properties to apply to your image.
*
* ```ts
* import { getImage } from "astro:assets";
* import myImage from "../assets/my_image.png";
*
* const optimizedImage = await getImage({src: myImage, width: 300, height: 300});
* ```
*
* In most cases, this error happens because parameters were passed directly instead of inside an object.
*/
export const ExpectedImageOptions = {
name: 'ExpectedImageOptions',
title: 'Expected image options.',
message: (options: string) =>
`Expected getImage() parameter to be an object. Received \`${options}\`.`,
} satisfies ErrorData;
/**
* @docs
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* @description
* Only one of `densities` or `widths` can be specified. Those attributes are used to construct a `srcset` attribute, which cannot have both `x` and `w` descriptors.
*/
export const IncompatibleDescriptorOptions = {
name: 'IncompatibleDescriptorOptions',
title: 'Cannot set both `densities` and `widths`',
message:
"Only one of `densities` or `widths` can be specified. In most cases, you'll probably want to use only `widths` if you require specific widths.",
hint: 'Those attributes are used to construct a `srcset` attribute, which cannot have both `x` and `w` descriptors.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* @description
* Astro could not find an image you imported. Often, this is simply caused by a typo in the path.
*
* Images in Markdown are relative to the current file. To refer to an image that is located in the same folder as the `.md` file, the path should start with `./`
*/
export const ImageNotFound = {
name: 'ImageNotFound',
title: 'Image not found.',
message: (imagePath: string) => `Could not find requested image \`${imagePath}\`. Does it exist?`,
hint: 'This is often caused by a typo in the image path. Please make sure the file exists, and is spelled correctly.',
} satisfies ErrorData;
/**
* @docs
* @message Could not process image metadata for `IMAGE_PATH`.
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* @description
* Astro could not process the metadata of an image you imported. This is often caused by a corrupted or malformed image and re-exporting the image from your image editor may fix this issue.
*/
export const NoImageMetadata = {
name: 'NoImageMetadata',
title: 'Could not process image metadata.',
message: (imagePath: string | undefined) =>
`Could not process image metadata${imagePath ? ` for \`${imagePath}\`` : ''}.`,
hint: 'This is often caused by a corrupted or malformed image. Re-exporting the image from your image editor may fix this issue.',
} satisfies ErrorData;
/**
* @docs
* @deprecated This error is no longer Markdown specific and as such, as been replaced by `ImageNotFound`
* @message
* Could not find requested image `IMAGE_PATH` at `FULL_IMAGE_PATH`.
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* @description
* Astro could not find an image you included in your Markdown content. Usually, this is simply caused by a typo in the path.
*
* Images in Markdown are relative to the current file. To refer to an image that is located in the same folder as the `.md` file, the path should start with `./`
*/
export const MarkdownImageNotFound = {
name: 'MarkdownImageNotFound',
title: 'Image not found.',
message: (imagePath: string, fullImagePath: string | undefined) =>
`Could not find requested image \`${imagePath}\`${
fullImagePath ? ` at \`${fullImagePath}\`.` : '.'
}`,
hint: 'This is often caused by a typo in the image path. Please make sure the file exists, and is spelled correctly.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* @description
* Astro could not transform one of your images. Often, this is caused by a corrupted or malformed image. Re-exporting the image from your image editor may fix this issue.
*
* Depending on the image service you are using, the stack trace may contain more information on the specific error encountered.
*/
export const CouldNotTransformImage = {
name: 'CouldNotTransformImage',
title: 'Could not transform image.',
message: (imagePath: string) =>
`Could not transform image \`${imagePath}\`. See the stack trace for more information.`,
hint: 'This is often caused by a corrupted or malformed image. Re-exporting the image from your image editor may fix this issue.',
} satisfies ErrorData;
/**
* @docs
* @description
* Making changes to the response, such as setting headers, cookies, and the status code cannot be done outside of page components.
*/
export const ResponseSentError = {
name: 'ResponseSentError',
title: 'Unable to set response.',
message: 'The response has already been sent to the browser and cannot be altered.',
} satisfies ErrorData;
/**
* @docs
* @description
* Thrown when the middleware does not return any data or call the `next` function.
*
* For example:
* ```ts
* import {defineMiddleware} from "astro:middleware";
* export const onRequest = defineMiddleware((context, _) => {
* // doesn't return anything or call `next`
* context.locals.someData = false;
* });
* ```
*/
export const MiddlewareNoDataOrNextCalled = {
name: 'MiddlewareNoDataOrNextCalled',
title: "The middleware didn't return a `Response`.",
message:
'Make sure your middleware returns a `Response` object, either directly or by returning the `Response` from calling the `next` function.',
} satisfies ErrorData;
/**
* @docs
* @description
* Thrown in development mode when middleware returns something that is not a `Response` object.
*
* For example:
* ```ts
* import {defineMiddleware} from "astro:middleware";
* export const onRequest = defineMiddleware(() => {
* return "string"
* });
* ```
*/
export const MiddlewareNotAResponse = {
name: 'MiddlewareNotAResponse',
title: 'The middleware returned something that is not a `Response` object.',
message: 'Any data returned from middleware must be a valid `Response` object.',
} satisfies ErrorData;
/**
* @docs
* @description
* Thrown when an endpoint does not return anything or returns an object that is not a `Response` object.
*
* An endpoint must return either a `Response`, or a `Promise` that resolves with a `Response`. For example:
* ```ts
* import type { APIContext } from 'astro';
*
* export async function GET({ request, url, cookies }: APIContext): Promise<Response> {
* return Response.json({
* success: true,
* result: 'Data from Astro Endpoint!'
* })
* }
* ```
*/
export const EndpointDidNotReturnAResponse = {
name: 'EndpointDidNotReturnAResponse',
title: 'The endpoint did not return a `Response`.',
message:
'An endpoint must return either a `Response`, or a `Promise` that resolves with a `Response`.',
} satisfies ErrorData;
/**
* @docs
* @description
*
* Thrown when `locals` is overwritten with something that is not an object
*
* For example:
* ```ts
* import {defineMiddleware} from "astro:middleware";
* export const onRequest = defineMiddleware((context, next) => {
* context.locals = 1541;
* return next();
* });
* ```
*/
export const LocalsNotAnObject = {
name: 'LocalsNotAnObject',
title: 'Value assigned to `locals` is not accepted.',
message:
'`locals` can only be assigned to an object. Other values like numbers, strings, etc. are not accepted.',
hint: 'If you tried to remove some information from the `locals` object, try to use `delete` or set the property to `undefined`.',
} satisfies ErrorData;
/**
* @docs
* @description
* Thrown when a value is being set as the `headers` field on the `ResponseInit` object available as `Astro.response`.
*/
export const AstroResponseHeadersReassigned = {
name: 'AstroResponseHeadersReassigned',
title: '`Astro.response.headers` must not be reassigned.',
message:
'Individual headers can be added to and removed from `Astro.response.headers`, but it must not be replaced with another instance of `Headers` altogether.',
hint: 'Consider using `Astro.response.headers.add()`, and `Astro.response.headers.delete()`.',
} satisfies ErrorData;
/**
* @docs
* @description
* Thrown in development mode when middleware throws an error while attempting to loading it.
*
* For example:
* ```ts
* import {defineMiddleware} from "astro:middleware";
* throw new Error("Error thrown while loading the middleware.")
* export const onRequest = defineMiddleware(() => {
* return "string"
* });
* ```
*/
export const MiddlewareCantBeLoaded = {
name: 'MiddlewareCantBeLoaded',
title: "Can't load the middleware.",
message: 'An unknown error was thrown while loading your middleware.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Images](https://docs.astro.build/en/guides/images/)
* @description
* When using the default image services, `Image`'s and `getImage`'s `src` parameter must be either an imported image or an URL, it cannot be a string of a filepath.
*
* For local images from content collections, you can use the [image() schema helper](https://docs.astro.build/en/guides/images/#images-in-content-collections) to resolve the images.
*
* ```astro
* ---
* import { Image } from "astro:assets";
* import myImage from "../my_image.png";
* ---
*
* <!-- GOOD: `src` is the full imported image. -->
* <Image src={myImage} alt="Cool image" />
*
* <!-- GOOD: `src` is a URL. -->
* <Image src="https://example.com/my_image.png" alt="Cool image" />
*
* <!-- BAD: `src` is an image's `src` path instead of the full image object. -->
* <Image src={myImage.src} alt="Cool image" />
*
* <!-- BAD: `src` is a string filepath. -->
* <Image src="../my_image.png" alt="Cool image" />
* ```
*/
export const LocalImageUsedWrongly = {
name: 'LocalImageUsedWrongly',
title: 'Local images must be imported.',
message: (imageFilePath: string) =>
`\`Image\`'s and \`getImage\`'s \`src\` parameter must be an imported image or an URL, it cannot be a string filepath. Received \`${imageFilePath}\`.`,
hint: 'If you want to use an image from your `src` folder, you need to either import it or if the image is coming from a content collection, use the [image() schema helper](https://docs.astro.build/en/guides/images/#images-in-content-collections). See https://docs.astro.build/en/guides/images/#src-required for more information on the `src` property.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Astro.glob](https://docs.astro.build/en/reference/api-reference/#astroglob)
* @description
* `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to achieve the same result.
*/
export const AstroGlobUsedOutside = {
name: 'AstroGlobUsedOutside',
title: 'Astro.glob() used outside of an Astro file.',
message: (globStr: string) =>
`\`Astro.glob(${globStr})\` can only be used in \`.astro\` files. \`import.meta.glob(${globStr})\` can be used instead to achieve a similar result.`,
hint: "See Vite's documentation on `import.meta.glob` for more information: https://vitejs.dev/guide/features.html#glob-import",
} satisfies ErrorData;
/**
* @docs
* @see
* - [Astro.glob](https://docs.astro.build/en/reference/api-reference/#astroglob)
* @description
* `Astro.glob()` did not return any matching files. There might be a typo in the glob pattern.
*/
export const AstroGlobNoMatch = {
name: 'AstroGlobNoMatch',
title: 'Astro.glob() did not match any files.',
message: (globStr: string) => `\`Astro.glob(${globStr})\` did not return any matching files.`,
hint: 'Check the pattern for typos.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Astro.redirect](https://docs.astro.build/en/reference/api-reference/#astroredirect)
* @description
* A redirect must be given a location with the `Location` header.
*/
export const RedirectWithNoLocation = {
name: 'RedirectWithNoLocation',
title: 'A redirect must be given a location with the `Location` header.',
} satisfies ErrorData;
/**
* @docs
* @see
* - [Dynamic routes](https://docs.astro.build/en/guides/routing/#dynamic-routes)
* @description
* A dynamic route param is invalid. This is often caused by an `undefined` parameter or a missing [rest parameter](https://docs.astro.build/en/guides/routing/#rest-parameters).
*/
export const InvalidDynamicRoute = {
name: 'InvalidDynamicRoute',
title: 'Invalid dynamic route.',
message: (route: string, invalidParam: string, received: string) =>
`The ${invalidParam} param for route ${route} is invalid. Received **${received}**.`,
} satisfies ErrorData;
/**
* @docs
* @see
* - [Default Image Service](https://docs.astro.build/en/guides/images/#default-image-service)
* - [Image Component](https://docs.astro.build/en/guides/images/#image--astroassets)
* - [Image Services API](https://docs.astro.build/en/reference/image-service-reference/)
* @description
* Sharp is the default image service used for `astro:assets`. When using a [strict package manager](https://pnpm.io/pnpm-vs-npm#npms-flat-tree) like pnpm, Sharp must be installed manually into your project in order to use image processing.
*
* If you are not using `astro:assets` for image processing, and do not wish to install Sharp, you can configure the following passthrough image service that does no processing:
*
* ```js
* import { defineConfig, passthroughImageService } from "astro/config";
* export default defineConfig({
* image: {
* service: passthroughImageService(),
* },
* });
* ```
*/
export const MissingSharp = {
name: 'MissingSharp',
title: 'Could not find Sharp.',
message:
'Could not find Sharp. Please install Sharp (`sharp`) manually into your project or migrate to another image service.',
hint: "See Sharp's installation instructions for more information: https://sharp.pixelplumbing.com/install. If you are not relying on `astro:assets` to optimize, transform, or process any images, you can configure a passthrough image service instead of installing Sharp. See https://docs.astro.build/en/reference/errors/missing-sharp for more information.\n\nSee https://docs.astro.build/en/guides/images/#default-image-service for more information on how to migrate to another image service.",
};
// No headings here, that way Vite errors are merged with Astro ones in the docs, which makes more sense to users.
// Vite Errors - 4xxx
/**
* @docs
* @see
* - [Vite troubleshooting guide](https://vitejs.dev/guide/troubleshooting.html)
* @description
* Vite encountered an unknown error while rendering your project. We unfortunately do not know what happened (or we would tell you!)
*
* If you can reliably cause this error to happen, we'd appreciate if you could [open an issue](https://astro.build/issues/)
*/
export const UnknownViteError = {
name: 'UnknownViteError',
title: 'Unknown Vite Error.',
} satisfies ErrorData;
/**
* @docs