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

vite 运行时报错 #1480

Closed
3 tasks done
biggestDreamerly opened this issue Oct 14, 2022 · 4 comments · Fixed by #1647
Closed
3 tasks done

vite 运行时报错 #1480

biggestDreamerly opened this issue Oct 14, 2022 · 4 comments · Fixed by #1647
Labels
need more info Further information is requested

Comments

@biggestDreamerly
Copy link

Describe the bug

The request url "/Users/allen/Desktop/lingo_code/turborepo/node_modules/.pnpm/registry.npmmirror.com+@docsearch+css@3.2.1/node_modules/@docsearch/css/dist/style.css" is outside of Vite serving allow list.

Reproduction

Expected behavior

正常运行

System Info

The request url "/Users/allen/Desktop/lingo_code/turborepo/node_modules/.pnpm/registry.npmmirror.com+@docsearch+css@3.2.1/node_modules/@docsearch/css/dist/style.css" is outside of Vite serving allow list.

Additional context

No response

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@biggestDreamerly biggestDreamerly added the bug: pending triage Maybe a bug, waiting for confirmation label Oct 14, 2022
@brc-dd
Copy link
Member

brc-dd commented Oct 14, 2022

Try creating a vite.config.ts file (in your docs directory if you're running vitepress build docs) with these contents:

export default {
  server: {
    fs: {
      allow: ['..']
    }
  }
}

@kiaking kiaking added need more info Further information is requested and removed bug: pending triage Maybe a bug, waiting for confirmation labels Oct 20, 2022
@gezhicui
Copy link

gezhicui commented Oct 23, 2022

Describe the bug

The request url "/Users/allen/Desktop/lingo_code/turborepo/node_modules/.pnpm/registry.npmmirror.com+@docsearch+css@3.2.1/node_modules/@docsearch/css/dist/style.css" is outside of Vite serving allow list.

Reproduction

Expected behavior

正常运行

System Info

The request url "/Users/allen/Desktop/lingo_code/turborepo/node_modules/.pnpm/registry.npmmirror.com+@docsearch+css@3.2.1/node_modules/@docsearch/css/dist/style.css" is outside of Vite serving allow list.

Additional context

No response

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

解决了吗

@kiaking
Copy link
Member

kiaking commented Oct 31, 2022

Closing due to inactivity

@kiaking kiaking closed this as not planned Won't fix, can't repro, duplicate, stale Oct 31, 2022
@kongxiangyan
Copy link

Hi guys, same issue here.

image

This problem is caused by createVitePressPlugin which internally build the vite config manually and seems uncorrectly specify the fs.allow list.

Fortunately, the vite config manually built will be merged with the user specified config. So-called user specified config is passed to createVitePressPlugin as a field in its first parameter -- siteConfig. createVitePressPlugin is invoked here, its first parameter is read by resolveConfig which internally using resolveUserConfig to read target vite config from valid config file in the project root or somewhere else.

The resolveUserConfig is the solution, according to its code:

Try creating a vite.config.ts file (in your docs directory if you're running vitepress build docs) with these contents:

export default {
  server: {
    fs: {
      allow: ['..']
    }
  }
}

@brc-dd 's solution will never work as expected. Wherever we put the vite.config.ts, it will be ignored constantly.

The only correct and temporary method is find our vitepress.config.ts, specify the related vite config as following:

import { cwd } from 'node:process'

import { searchForWorkspaceRoot } from 'vite'
import { defineConfig } from 'vitepress'

const vitePressConfig = defineConfig({
  vite: {
    server: {
      fs: {
        allow: [searchForWorkspaceRoot(cwd())]
      }
    }
  }
  // ...yourCustomConfig
})

export vitePressConfig

Congratulations! Works well 🎉

References


Finally, the code here in VitePress should be fixed. searchForWorkspaceRoot(cwd()) Should be add to the allow list.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need more info Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants