Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Vite dev server returns 403 for a file outside the allow list

ErrorThe 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.

  • Applies to Vite 7, Vite 8
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.json
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The 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. 3The 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

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.json

2Fix

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 dev

Confirmed by vite.dev

Did this fix it?

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 dev

Confirmed by vite.dev

Did this fix it?

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 dev

Confirmed by vite.dev

Did this fix it?

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 fix

Web 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.