DenoDDeno
Powered by
j4J
Denoβ€’2y agoβ€’
1 reply
j4

Vite plugin's global variables are `undefined` when using Deno

Anyone run across this before? Running Deno 2 and Vite 6beta.

I built a third-party Vite plugin, and now I'm testing it in a "native" Deno project (deno.json, not package.json, etc). However, all of the packages and dependencies are from npm. My Vite plugin defines a global like so.
...
return {
  define: {
    'XINK_VITE_MODE': JSON.stringify(mode)
  }
}
...
...
return {
  define: {
    'XINK_VITE_MODE': JSON.stringify(mode)
  }
}
...

In another part of my plugin package's code, not within the vite plugin definition itself, I grab the value during runtime, but it's logging
undefined
undefined
. This works fine when using Bun. I also tried doing
globalThis.XINK_VITE_MODE
globalThis.XINK_VITE_MODE
as well, since Vite's intellisense said it's supposed be available on
window
window
during
dev
dev
.
export const initRouter = async () => {
  const mode = XINK_VITE_MODE
  console.log('Vite mode is:', mode)
...
}
export const initRouter = async () => {
  const mode = XINK_VITE_MODE
  console.log('Vite mode is:', mode)
...
}
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Deno + Vite + DenoKV
AndiAAndi / help
2y ago
Deno Vite plugin not working Windows
DanCuatroDDanCuatro / help
11mo ago
Deno 2 compatibility with TanStackRouter vite plugin
RedSonRRedSon / help
16mo ago