nitrojs / nitrojs/nitro

[vite] globalThis.__VITE_MANIFEST__ is undefined

Open
#3,656 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

v3
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

This value is not getting set in production on the server. The workaround is to use a plugin like:

const manifestPlugin = (): Plugin => {
	let manifest = "{}";
	const id = "#vite-manifest";
	const resolvedId = `\0${id}`;
	return {
		name: "manifest",
		applyToEnvironment(e) {
			return e.name === "nitro"
		},
config() { return { manifest: true } },
		resolveId(possibleId) {
			if (possibleId === id) {
				return resolvedId
			}
		},
		load(id) {
			if (id === resolvedId) {
				return `export default ${manifest}`
			}
		},
		async buildStart(c) {
			manifest = await fs.readFile("./.output/public/.vite/manifest.json", "utf-8");
		},
	}
}

and importing the manifest from "#vite-manifest"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the production server behavior described in the issue and tracing where the Vite manifest is expected to be exposed. Compare that path with the supplied plugin workaround. Done means globalThis.VITE_MANIFEST is defined in production without requiring the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.