Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File outside of Vite serving allow list #18291

Closed
7 tasks done
lungarella-raffaele opened this issue Oct 6, 2024 · 1 comment
Closed
7 tasks done

File outside of Vite serving allow list #18291

lungarella-raffaele opened this issue Oct 6, 2024 · 1 comment

Comments

@lungarella-raffaele
Copy link

lungarella-raffaele commented Oct 6, 2024

Describe the bug

I am building a Svelte component library, I am using Storybook and would like to import a .css file inside my components, more precisely inside the preview.ts file of storybook. My .css file is inside my static folder, when I try to import it I get the error:

The request url "/Users/myapp/static/app.css" is outside of Vite serving allow list.

- /Users/myapp/src/lib
- /Users/myapp/src/routes
- /Users/myapp/.svelte-kit
- /Users/myapp/src
- /Users/myapp/node_modules
- /Users/myapp/.storybook

I read the docs and to fix this issue it seems like the solution would be to put the file inside my vite serving allow list like this:

  server: {
    fs: {
      allow: [
        searchForWorkspaceRoot(process.cwd()),
        "/static/css/bootstrap-italia-custom.min.css",
      ],
    },
  },

But nothing seems to change, I tried putting the full url, I tried by selecting only the parent folder, I tried without the searchForWorkspaceRoot utility, but nothing seems to woek. What am I doing wrong?

Reproduction

Small repo created from npm create svelte@latest with only storybook added as dependency: https://github.com/lungarella-raffaele/vite-issue to recreate the problem

Steps to reproduce

npm run storybook

Vite cannot serve the app.css file even though it is specified in the configs

System Info

node: v21.7.3
MacOs Sequoia

Used Package Manager

npm

Logs

No response

Validations

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Oct 6, 2024

Probably storybook is manipulating server.fs.allow, so you should check with them.
Usually server.fs.allow should be process.cwd() = "/Users/myapp" and that shouldn't cause the issue.

For example, you can enforce this by the plugin for the time being:

export default defineConfig({
  plugins: [
    sveltekit(),
    {
      name: "config",
      enforce: "post",
      config(config) {
        config.server.fs.allow = [process.cwd()];
      },
    }
  ],
})

@hi-ogawa hi-ogawa closed this as completed Oct 6, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants