Vite dev server returns 403 for a file outside the allow list
The request url "/path/to/file" is outside of Vite serving allow list.Short answer
Vite serves files only from its workspace root and from files imported by allowed ones. A 403 means the requested file sits outside that root. Make Vite detect the real workspace root, or list the extra folder in server.fs.allow, and keep searchForWorkspaceRoot so auto detection still applies.
Fix it fast
1Find out which cause you have
Note the path in the error, then find which workspace root Vite uses for this project: the nearest folder above it with a workspaces field, lerna.json or pnpm-workspace.yaml.
ls ../pnpm-workspace.yaml ../lerna.json ../package.json2Match what you see, then jump to its fix
- 1
The refused file is in a sibling package, or in a folder above the package, such as a submodule or the repo rootVite picked the project folder, not the monorepo rootFix - 2
The refused path is a folder you chose to keep outside the root, such as a shared assets directoryA folder is simply not in the allowed listFix - 3
The error began after you added server.fs.allow for one folder, and files from the root now failAn allow list you set earlier hides the workspace rootFix
- 1
What does the error look like?
The request url "/path/to/file" is outside of Vite serving allow list.
Cause 1 of 3
Vite picked the project folder, not the monorepo root
1Check
Vite looks upward for a workspace root. It accepts a folder with a workspaces field in package.json, a lerna.json, or a pnpm-workspace.yaml. Without one, it falls back to the project root.
ls ../pnpm-workspace.yaml ../lerna.json 2>/dev/null
grep -n workspaces ../package.json2Fix
Add the workspace marker file at the true root so detection finds it, for example a pnpm-workspace.yaml listing your packages.
# pnpm-workspace.yaml at the repo root
packages:
- 'packages/*'
- 'apps/*'3Verify
Restart the dev server and open the page again; the request no longer returns 403.
npm run devConfirmed by vite.dev
Cause 2 of 3
A folder is simply not in the allowed list
1Check
Find which directory the file lives in and whether any code imports it. Files imported by an allowed file are served; direct requests to other paths are refused.
grep -n -A6 "fs" vite.config.*2Fix
Add that directory to server.fs.allow. Setting this option turns automatic workspace root detection off, so add the detected root back with searchForWorkspaceRoot.
// vite.config.js
import { defineConfig, searchForWorkspaceRoot } from 'vite'
export default defineConfig({
server: {
fs: {
allow: [
searchForWorkspaceRoot(process.cwd()),
'/path/to/shared-assets',
],
},
},
})3Verify
Restart the server and request the file again.
npm run devConfirmed by vite.dev
Cause 3 of 3
An allow list you set earlier hides the workspace root
1Check
When server.fs.allow is given, Vite stops searching for the workspace root. Only the paths you listed remain.
grep -n "allow" vite.config.*2Fix
Start the list with searchForWorkspaceRoot(process.cwd()) so the old default is kept, then add your own paths after it.
allow: [
searchForWorkspaceRoot(process.cwd()),
// your custom rules
]3Verify
Restart the dev server; both the old and the new paths load.
npm run devConfirmed by vite.dev
How do I stop it coming back?
- Put pnpm-workspace.yaml, lerna.json or a workspaces field at the real root of every monorepo.
- When you set server.fs.allow, always include searchForWorkspaceRoot first.
- Do not turn server.fs.strict off to silence the error; it also removes the protection around files Vite should not serve.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Web apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Apollo Client is blocked by CORS when the GraphQL server runs on AWS Lambda
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apollo Server does not set CORS for you when it runs behind a framework or integration, and on Lambda that layer is API Gateway.
5 causes, each with a fixWeb apps
A POST to a Google Apps Script web app returns 405 or a CORS error
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apps Script web apps run doPost for POST and doGet for GET, and the Apps Script guides describe no other entry points.
3 causes, each with a fix