Skip to content

fix: populate globalThis with defines in Vitest#16224

Open
elliott-with-the-longest-name-on-github wants to merge 3 commits into
version-3from
elliott/populate-globalthis-vitest
Open

fix: populate globalThis with defines in Vitest#16224
elliott-with-the-longest-name-on-github wants to merge 3 commits into
version-3from
elliott/populate-globalthis-vitest

Conversation

@elliott-with-the-longest-name-on-github

Copy link
Copy Markdown
Contributor

Closes #16214

Sets defines on globalThis when we detect that Vitest is running, since it "helpfully" deletes them for us.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 3, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from be586f3:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/be586f39b6461f43cd834d272782d5491dfcf704

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16224

@changeset-bot

changeset-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: be586f3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@elliott-with-the-longest-name-on-github

Copy link
Copy Markdown
Contributor Author

@MaddyGuthridge can you install using the pkg.svelte.dev link above and let me know if it fixes your issue? I think it should...

@svelte-docs-bot

Copy link
Copy Markdown

@MaddyGuthridge

Copy link
Copy Markdown

I'll give this a go after work today

Comment thread packages/kit/src/exports/vite/index.js Outdated
Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
Comment thread packages/kit/src/exports/vite/index.js Outdated
@MaddyGuthridge

Copy link
Copy Markdown

I've tried it out, but had some issues:

  • This change targets v3 of svelte-kit, which means there are other breaking changes, none of which appear in the mainline documentation yet. Is a backport to the v2 branch possible?
  • The JSON error mentioned by the vercel bot.
$ npm t
> kit-template-default@0.0.1 test
> vitest run


⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
SyntaxError: Unexpected token 'g', "globalThis"... is not valid JSON
    at JSON.parse (<anonymous>)
    at BasicMinimalPluginContext.handler (file:///home/maddy/Downloads/sveltejs-kit-template-default-fann5ee8/node_modules/@sveltejs/kit/src/exports/vite/index.js:506:67)
    at async runConfigHook (file:///home/maddy/Downloads/sveltejs-kit-template-default-fann5ee8/node_modules/vite/dist/node/chunks/node.js:35760:15)
    at async resolveConfig (file:///home/maddy/Downloads/sveltejs-kit-template-default-fann5ee8/node_modules/vite/dist/node/chunks/node.js:35195:11)
    at async _createServer (file:///home/maddy/Downloads/sveltejs-kit-template-default-fann5ee8/node_modules/vite/dist/node/chunks/node.js:25332:65)
    at async createViteServer (file:///home/maddy/Downloads/sveltejs-kit-template-default-fann5ee8/node_modules/vitest/dist/chunks/cli-api.24X8XwN1.js:8835:17)
    at async createVitest (file:///home/maddy/Downloads/sveltejs-kit-template-default-fann5ee8/node_modules/vitest/dist/chunks/cli-api.24X8XwN1.js:14221:18)
    at async prepareVitest (file:///home/maddy/Downloads/sveltejs-kit-template-default-fann5ee8/node_modules/vitest/dist/chunks/cli-api.24X8XwN1.js:14588:14)
    at async startVitest (file:///home/maddy/Downloads/sveltejs-kit-template-default-fann5ee8/node_modules/vitest/dist/chunks/cli-api.24X8XwN1.js:14531:14)
    at async start (file:///home/maddy/Downloads/sveltejs-kit-template-default-fann5ee8/node_modules/vitest/dist/chunks/cac.D3xHeqeL.js:2340:15)

@dummdidumm dummdidumm changed the base branch from version-3 to main July 3, 2026 20:53
@dummdidumm dummdidumm changed the base branch from main to version-3 July 3, 2026 20:54

@dummdidumm dummdidumm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should target main (I briefly tried through the UI but that will try to add all of version-3, too), otherwise lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants