Home / Function/ generateHint() — astro Function Reference

generateHint() — astro Function Reference

Architecture documentation for the generateHint() function in utils.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  bbf62356_656f_e004_5e19_86d1d5889e42["generateHint()"]
  6382d0b9_8ae6_1f6a_25b6_41a3e8e6de51["utils.ts"]
  bbf62356_656f_e004_5e19_86d1d5889e42 -->|defined in| 6382d0b9_8ae6_1f6a_25b6_41a3e8e6de51
  8d0d4acd_8384_a2c6_5b17_55868e5cf72d["collectErrorMetadata()"]
  8d0d4acd_8384_a2c6_5b17_55868e5cf72d -->|calls| bbf62356_656f_e004_5e19_86d1d5889e42
  style bbf62356_656f_e004_5e19_86d1d5889e42 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/errors/dev/utils.ts lines 140–159

function generateHint(err: ErrorWithMetadata): string | undefined {
	const commonBrowserAPIs = ['document', 'window'];

	if (/Unknown file extension "\.(?:jsx|vue|svelte|astro|css)" for /.test(err.message)) {
		return 'You likely need to add this package to `vite.ssr.noExternal` in your astro config file.';
	} else if (commonBrowserAPIs.some((api) => err.toString().includes(api))) {
		const hint = `Browser APIs are not available on the server.

${
	err.loc?.file?.endsWith('.astro')
		? 'Move your code to a <script> tag outside of the frontmatter, so the code runs on the client.'
		: 'If the code is in a framework component, try to access these objects after rendering using lifecycle methods or use a `client:only` directive to make the component exclusively run on the client.'
}

See https://docs.astro.build/en/guides/troubleshooting/#document-or-window-is-not-defined for more information.
		`;
		return hint;
	}
	return err.hint;
}

Domain

Subdomains

Frequently Asked Questions

What does generateHint() do?
generateHint() is a function in the astro codebase, defined in packages/astro/src/core/errors/dev/utils.ts.
Where is generateHint() defined?
generateHint() is defined in packages/astro/src/core/errors/dev/utils.ts at line 140.
What calls generateHint()?
generateHint() is called by 1 function(s): collectErrorMetadata.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free