new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Vite · Guide · all subjects

troubleshooting and configuration

47 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

server.host type and default value

server.host has type string | boolean with default value 'localhost'. It specifies which IP addresses the server should listen on.

server.host listen on all addresses

Set server.host to 0.0.0.0 or true to listen on all addresses, including LAN and public addresses. This can be set via CLI using --host 0.0.0.0 or --host.

localhost DNS resolution issue with server.host

When localhost is used as server.host, Node.js's dns.setDefaultResultOrder changes how DNS-resolved addresses are ordered, and browsers may use a different resolved address than the one Vite is listening to. Vite prints the resolved address when it differs.

Wildcard hosts priority issue with server.host

When wildcard hosts like 0.0.0.0 are used with server.host, servers listening on non-wildcard hosts take priority over those listening on wildcard hosts, which may cause other servers to respond instead of Vite.

server.allowedHosts type and default

server.allowedHosts has type string[] | true with default value []. It specifies hostnames that Vite is allowed to respond to. localhost and domains under .localhost and all IP addresses are allowed by default.

server.allowedHosts dot prefix behavior

If a string in server.allowedHosts starts with a dot, it will allow that hostname without the dot and all subdomains under the hostname. For example, .example.com will allow example.com, foo.example.com, and foo.bar.example.com.

server.allowedHosts set to true security risk

Setting server.allowedHosts to true allows any website to send requests to the dev server through DNS rebinding attacks, allowing them to download source code and content. An explicit list of allowed hosts is recommended. See GHSA-vg6x-rcgg-rjx6 for details.

server.allowedHosts via environment variable

The environment variable __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS can be set to add additional allowed hosts. Use commas to separate multiple hosts, for example: host1.example.com,host2.example.com.

server.port type and default value

server.port has type number with default value 5173. It specifies the server port. If the port is already in use, Vite will automatically try the next available port so the actual port may differ from the configured value.

server.strictPort behavior

server.strictPort is a boolean option. When set to true, Vite will exit if the port is already in use, instead of automatically trying the next available port.

server.https type and usage

server.https has type https.ServerOptions. It enables TLS + HTTP/2 with the value being an options object passed to https.createServer(). A valid certificate is needed; @vitejs/plugin-basic-ssl can be added for basic setup with self-signed certificate, but creating own certificates is recommended.

server.open type and behavior

server.open has type boolean | string. When true, it automatically opens the app in the browser on server start. When the value is a string, it will be used as the URL's pathname.

server.open browser configuration

With server.open, you can set env process.env.BROWSER to specify a browser (e.g. firefox) and process.env.BROWSER_ARGS to pass additional arguments (e.g. --incognito). BROWSER and BROWSER_ARGS are also special environment variables that can be set in .env file.

server.proxy type and basic behavior

server.proxy has type Record<string, string | ProxyOptions>. It expects an object of key: options pairs. Any requests whose request path starts with that key will be proxied to the specified target. If the key starts with ^, it will be interpreted as a RegExp.

server.proxy configure option

The configure option in server.proxy can be used to access the proxy instance, which will be an instance of 'http-proxy-3'.

server.proxy base prefix requirement

If using non-relative base, each key in server.proxy must be prefixed with that base.

server.proxy request transformation

If a request matches any of the configured proxy rules in server.proxy, the request won't be transformed by Vite.

server.proxy WebSocket example

To proxy websockets or socket.io with server.proxy, set ws: true in the proxy configuration, for example: '/socket.io': { target: 'ws://localhost:5174', ws: true }. Exercise caution with rewriteWsOrigin as it can leave proxying open to CSRF attacks.

server.cors type and default value

server.cors has type boolean | CorsOptions with default value { origin: /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/ } which allows localhost, 127.0.0.1 and ::1. Pass an options object to fine tune the behavior or true to allow any origin.

server.cors set to true security risk

Setting server.cors to true allows any website to send requests to the dev server and download source code and content. An explicit list of allowed origins is recommended.

server.headers type and purpose

server.headers has type OutgoingHttpHeaders and is used to specify server response headers.

server.forwardConsole type and default

server.forwardConsole has type boolean | { unhandledErrors?: boolean, logLevels?: ('error' | 'warn' | 'info' | 'log' | 'debug')[] } with default auto (true when an AI coding agent is detected, otherwise false). It forwards browser runtime events to the Vite server console during development.

server.forwardConsole true behavior

When server.forwardConsole is set to true, it enables forwarding unhandled errors and console.error / console.warn logs.

server.forwardConsole unhandledErrors option

The unhandledErrors option in server.forwardConsole controls forwarding uncaught exceptions and unhandled promise rejections.

server.forwardConsole logLevels option

The logLevels option in server.forwardConsole controls which console.* calls are forwarded. Possible values are 'error', 'warn', 'info', 'log', 'debug'.

server.warmup type and purpose

server.warmup has type { clientFiles?: string[], ssrFiles?: string[] }. It warms up files to transform and cache results in advance, improving initial page load during server starts and preventing transform waterfalls.

server.warmup clientFiles and ssrFiles

In server.warmup, clientFiles are files used in the client only, while ssrFiles are files used in SSR only. They accept arrays of file paths or tinyglobby patterns relative to the root.

server.watch type and purpose

server.watch has type object | null. It specifies file system watcher options to pass to chokidar.

server.watch default ignored directories

The Vite server watcher watches the root and skips .git/, node_modules/, test-results/, and Vite's cacheDir and build.outDir directories by default.

server.watch null behavior

When server.watch is set to null, no files will be watched. server.watcher will provide a compatible event emitter, but calling add or unwatch will have no effect.

server.watch node_modules limitation

It is currently not possible to watch files and packages in node_modules with server.watch. See issue #8619 for progress and workarounds.

server.watch WSL2 file editing issue

When running Vite on WSL2, file system watching does not work when a file is edited by Windows applications (non-WSL2 process). This is due to a WSL2 limitation. This also applies to running on Docker with a WSL2 backend.

server.watch WSL2 solutions

To fix file watching on WSL2, either: use WSL2 applications to edit files and move the project folder outside of a Windows filesystem to improve performance; or set { usePolling: true }, noting that usePolling leads to high CPU utilization.

server.middlewareMode type and default

server.middlewareMode has type boolean | { server: http.Server } with default false. It creates Vite server in middleware mode.

server.middlewareMode with proxy setup

If proxy is setup for WebSocket in server.middlewareMode, the server should be provided to bind the proxy correctly.

server.fs.strict type and default

server.fs.strict has type boolean with default true (enabled by default since Vite 2.7). It restricts serving files outside of workspace root.

server.fs.allow type and purpose

server.fs.allow has type string[]. It restricts files that could be served via /@fs/. When server.fs.strict is set to true, accessing files outside this directory list that aren't imported from an allowed file will result in a 403.

server.fs.allow workspace detection

Vite searches for the root of the potential workspace. A valid workspace meets the following conditions, otherwise will fall back to the project root: contains workspaces field in package.json; or contains one of: lerna.json, pnpm-workspace.yaml.

server.fs.allow searchForWorkspaceRoot utility

When server.fs.allow is specified, auto workspace root detection is disabled. The utility searchForWorkspaceRoot is exposed to search up for workspace root and extend the original behavior.

server.fs.deny type and default value

server.fs.deny has type string[] with default ['.env', '.env.*', '*.{crt,pem,key,p12,pfx,cer,der}', '.npmrc', '.yarnrc.yml', '**/.git/**']. It is a blocklist for sensitive files being restricted from being served by Vite dev server.

server.fs.deny priority over allow

server.fs.deny has higher priority than server.fs.allow. Picomatch patterns are supported in server.fs.deny.

server.fs.deny public directory exemption

The blocklist in server.fs.deny does not apply to the public directory. All files in the public directory are served without any filtering, since they are copied directly to the output directory during build.

server.fs.deny query parameter stripping

The deny filter in server.fs.deny is applied against the module id and the id with query parameters stripped. Since a plugin can read files from any files in its load hook, Vite cannot guarantee that a denied file is inaccessible through an alternative path.

server.origin type and purpose

server.origin has type string. It defines the origin of the generated asset URLs during development.

server.sourcemapIgnoreList type and default

server.sourcemapIgnoreList has type false | (sourcePath: string, sourcemapPath: string) => boolean with default (sourcePath) => sourcePath.includes('node_modules'). It determines whether to ignore source files in the server sourcemap, used to populate the x_google_ignoreList source map extension.

server.sourcemapIgnoreList path format

server.sourcemapIgnoreList is called with an absolute path for sourcePath, unlike build.rolldownOptions.output.sourcemapIgnoreList which is called with a relative path. During dev, most modules have the map and source in the same folder, making absolute paths convenient to use.

server.sourcemapIgnoreList independent configuration

server.sourcemapIgnoreList and build.rolldownOptions.output.sourcemapIgnoreList need to be set independently. server.sourcemapIgnoreList is a server-only config and doesn't get its default value from the defined Rolldown options.

Give your agent this brain