Provide a better error message when no jsx renderer configured (#4603)
* Provide a better error message when no jsx renderer configured * Add a changeset
This commit is contained in:
parent
592de3d703
commit
36dee7169b
2 changed files with 19 additions and 4 deletions
5
.changeset/tough-zoos-bathe.md
Normal file
5
.changeset/tough-zoos-bathe.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix error when no JSX renderer configured
|
|
@ -160,14 +160,14 @@ export default function jsx({ config, logging }: AstroPluginJSXOptions): Plugin
|
||||||
let astroJSXRenderer: AstroRenderer;
|
let astroJSXRenderer: AstroRenderer;
|
||||||
// The first JSX renderer provided is considered the default renderer.
|
// The first JSX renderer provided is considered the default renderer.
|
||||||
// This is a useful reference for when the user only gives a single render.
|
// This is a useful reference for when the user only gives a single render.
|
||||||
let defaultJSXRendererEntry: [string, AstroRenderer];
|
let defaultJSXRendererEntry: [string, AstroRenderer] | undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'astro:jsx',
|
name: 'astro:jsx',
|
||||||
enforce: 'pre', // run transforms before other plugins
|
enforce: 'pre', // run transforms before other plugins
|
||||||
async configResolved(resolvedConfig) {
|
async configResolved(resolvedConfig) {
|
||||||
viteConfig = resolvedConfig;
|
viteConfig = resolvedConfig;
|
||||||
const possibleRenderers = await collectJSXRenderers(config._ctx.renderers);
|
const possibleRenderers = collectJSXRenderers(config._ctx.renderers);
|
||||||
for (const [importSource, renderer] of possibleRenderers) {
|
for (const [importSource, renderer] of possibleRenderers) {
|
||||||
jsxRenderers.set(importSource, renderer);
|
jsxRenderers.set(importSource, renderer);
|
||||||
if (importSource === 'astro') {
|
if (importSource === 'astro') {
|
||||||
|
@ -224,8 +224,8 @@ export default function jsx({ config, logging }: AstroPluginJSXOptions): Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we still can’t tell the import source, now is the time to throw an error.
|
// if we still can’t tell the import source, now is the time to throw an error.
|
||||||
if (!importSource) {
|
if (!importSource && defaultJSXRendererEntry) {
|
||||||
const [defaultRendererName] = defaultJSXRendererEntry[0];
|
const [defaultRendererName] = defaultJSXRendererEntry;
|
||||||
error(
|
error(
|
||||||
logging,
|
logging,
|
||||||
'renderer',
|
'renderer',
|
||||||
|
@ -234,6 +234,16 @@ Unable to resolve a renderer that handles this file! With more than one renderer
|
||||||
Add ${colors.cyan(
|
Add ${colors.cyan(
|
||||||
IMPORT_STATEMENTS[defaultRendererName] || `import '${defaultRendererName}';`
|
IMPORT_STATEMENTS[defaultRendererName] || `import '${defaultRendererName}';`
|
||||||
)} or ${colors.cyan(`/* jsxImportSource: ${defaultRendererName} */`)} to this file.
|
)} or ${colors.cyan(`/* jsxImportSource: ${defaultRendererName} */`)} to this file.
|
||||||
|
`
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
} else if(!importSource) {
|
||||||
|
error(
|
||||||
|
logging,
|
||||||
|
'renderer',
|
||||||
|
`${colors.yellow(id)}
|
||||||
|
Unable to find a renderer for JSX. Do you have one configured in your Astro config? See this page to learn how:
|
||||||
|
https://docs.astro.build/en/core-concepts/framework-components/#installing-integrations
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue