I have setup a pnpm workspace with a number of projects that I am adding as git submodules.

A previously working Nuxt project suddenly started giving the error The request url * is outside of Vite serving allow list for multiple files, including dependencies installed as pnpm modules inside the workspace node_modules folder.

The only change had been to initialise my project as a git repository.

I was expecting the dev server to keep working, and that changes to git would not have any effect.

The project still builds ok.

4

There are 4 best solutions below

8
On BEST ANSWER

Vite uses "auto workspace root detection" to figure out where your project root is.

Within a pnpm workspace your project's node_modules will be installed at the root of the workspace and not within your project folder.

As soon as you initialise a git repository for your project within the workspace then vite seems to auto detect this as your project root and not the workspace (which I'm presuming is initialised as a git repo which you are adding submodules to).

The solution is to specify the pnpm workspace as an allowed directory for the vite server

export default defineNuxtConfig({
    vite: {
        server: {
            fs: {
                allow: ["/home/user/Monorepo"]
            }
        }
    }
})

vite: server-fs-allow

0
On

Allow file serving outside of project root with relative path:

server: {
  fs: {
    // Allow serving files from one level up to the project root
    allow: ['..'],
  },
},
0
On

This is the recommanded way :

import { defineConfig, searchForWorkspaceRoot } from 'vite'

export default defineConfig({
  server: {
    fs: {
      allow: [
        // search up for workspace root
        searchForWorkspaceRoot(process.cwd()),
        // your custom rules
        '/path/to/custom/allow',
      ],
    },
  },
})
0
On

If you are using svelte kit, the error might happen when trying to import a file from outside the src folder.

So if you can move said file to that folder, it's an easier fix, otherwise, the answer is @a2k42 's solution.