{"id":22559,"library":"vite-hot-client","title":"vite-hot-client","description":"A lightweight utility (v2.1.0, actively maintained) that allows you to access Vite's HMR API (`import.meta.hot`) at runtime, even in contexts where `import.meta.hot` is not directly available (e.g., inside iframes, worker threads, or dynamically evaluated code). It provides `hot`, `createHotContext`, and `tryCreateHotContext` functions. Key differentiator: solves the problem of accessing Vite's HMR client from outside standard Vite-managed modules, enabling dev tools like `vite-plugin-inspect` to communicate with the dev server over HMR. Requires `vite` ^2.6.0 || ^3.0.0 || ^4.0.0 || ^5.0.0-0 || ^6.0.0-0 || ^7.0.0-0. Ships TypeScript definitions and is ESM-only since v2.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/antfu/vite-hot-client","tags":["javascript","typescript"],"install":[{"cmd":"npm install vite-hot-client","lang":"bash","label":"npm"},{"cmd":"yarn add vite-hot-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-hot-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; uses Vite's HMR internals.","package":"vite","optional":false}],"imports":[{"note":"ESM-only since v2; require() will throw.","wrong":"const { hot } = require('vite-hot-client')","symbol":"hot","correct":"import { hot } from 'vite-hot-client'"},{"symbol":"createHotContext","correct":"import { createHotContext } from 'vite-hot-client'"},{"note":"Introduced in v0.2.0; older versions only have createHotContext.","symbol":"tryCreateHotContext","correct":"import { tryCreateHotContext } from 'vite-hot-client'"}],"quickstart":{"code":"import { hot, createHotContext } from 'vite-hot-client'\n\n// 1) Use pre-exported 'hot' (works when module has import.meta.hot)\nif (hot) {\n  console.log('HMR connected')\n  hot.on('vite:beforeFullReload', () => console.log('reloading'))\n}\n\n// 2) Create context for a virtual module path (e.g., for custom UI)\nconst ctx = createHotContext('/@my-plugin/client')\nif (ctx) {\n  ctx.send('custom:update', { data: 'hello' })\n}","lang":"typescript","description":"Shows using the 'hot' export and createHotContext() for custom HMR communication."},"warnings":[{"fix":"Use ES module imports (import { hot } from 'vite-hot-client'); remove any require() calls.","message":"v2.0.0 adopted Epoch SemVer; previous version was v0.x. Imports unchanged but package is now ESM-only.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace hot.on(...) with createHotContext('/path/to/module').on(...) or use the exported 'hot' (which is pre-bound to the current module).","message":"v0.2.0 removed the anonymous hot context (hot without arguments). Must use createHotContext(path) or tryCreateHotContext() instead.","severity":"breaking","affected_versions":">=0.2.0 <0.2.0"},{"fix":"Use tryCreateHotContext to safely create a context, which returns null instead of throwing.","message":"tryCreateHotContext was added in v0.2.0; older createHotContext may throw if Vite is not available.","severity":"deprecated","affected_versions":"<0.2.0"},{"fix":"Guard usage with process.env.NODE_ENV !== 'production' or similar.","message":"The package does not work in production builds; it's only for development (Vite dev server).","severity":"gotcha","affected_versions":"*"},{"fix":"Check if hot is truthy before using: if (hot) { ... }","message":"import.meta.hot may be undefined in some environments (e.g., SSR, tests). Always check hot or the returned context for null.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'-0':88,90,92 '2.6.0':84 '3.0.0':85 '4.0.0':86 '5.0.0':87 '6.0.0':89 '7.0.0':91 'access':15,54 'activ':9 'allow':12 'api':19 'avail':31 'client':4,58 'code':40 'communic':75 'context':25 'createhotcontext':44 'definit':95 'dev':67,78 'differenti':49 'direct':30 'dynam':38 'e.g':32 'enabl':66 'esm':99 'esm-on':98 'evalu':39 'even':23 'function':47 'hmr':18,57,81 'hot':3,43 'ifram':34 'import.meta.hot':20,27 'insid':33 'inspect':73 'javascript':103 'key':48 'lightweight':6 'like':69 'maintain':10 'manag':64 'modul':65 'outsid':60 'plugin':72 'problem':52 'provid':42 'requir':82 'runtim':22 'server':79 'ship':93 'sinc':101 'solv':50 'standard':61 'thread':36 'tool':68 'trycreatehotcontext':46 'typescript':94,104 'util':7 'v2':102 'v2.1.0':8 'vite':2,16,55,63,71,83 'vite-hot-cli':1 'vite-manag':62 'vite-plugin-inspect':70 'worker':35","created_at":"2026-04-27T17:05:48.605009+00:00","updated_at":"2026-04-27T17:05:48.605009+00:00","problems":[{"fix":"Set 'type': 'module' in package.json or use .mjs extension.","cause":"Using import in a CommonJS file or Node.js without 'type: module'.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Ensure vite-hot-client is symlinked or installed correctly; it is ESM-only since v2. Use dynamic import() if necessary.","cause":"Using named import from a CommonJS build of vite-hot-client.","error":"The requested module 'vite-hot-client' does not provide an export named 'hot'"},{"fix":"Access 'hot' inside a function or after the module is loaded; it's set synchronously when import.meta.hot is available.","cause":"Accessing the exported 'hot' before it's assigned (e.g., in top-level code during module evaluation).","error":"ReferenceError: hot is not defined"},{"fix":"Check for null: const ctx = createHotContext(...); if (ctx) { ctx.on(...) }","cause":"createHotContext or hot returns null when Vite HMR is not available, but code attempts to call methods on null.","error":"TypeError: Cannot read properties of null (reading 'on')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/antfu/vite-hot-client","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/vite-hot-client","openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-18","next_check":"2026-07-26","install_tag":null}}