Skip to content

fix: populate globalThis with defines in Vitest - #16224

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

fix: populate globalThis with defines in Vitest#16224
elliott-with-the-longest-name-on-github wants to merge 4 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 dc7b03c:

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

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

⚠️ No Changeset found

Latest commit: dc7b03c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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

@Rich-Harris

Copy link
Copy Markdown
Member

figured it'd be easiest to just open a new PR: #16246

Rich-Harris added a commit that referenced this pull request Jul 6, 2026
@Rich-Harris

Copy link
Copy Markdown
Member

merged #16246, closing

@Rich-Harris Rich-Harris closed this Jul 6, 2026
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