admin管理员组

文章数量:1442602

When building vite react in docker-compose application, a message appears when opening the web-site page Blocked request. This host ("frontend_web") is not allowed. To allow this host, add "frontend_web" to `server.allowedHosts` in vite.config.js.

I tried to use "vite-plugin-allowed-hosts" but it gives me an error when building the docker-container [ERROR] Failed to resolve entry for package "vite-plugin-allowed-hosts". The package may have incorrect main/module/exports specified in its package.json. [plugin externalize-deps]

When building vite react in docker-compose application, a message appears when opening the web-site page Blocked request. This host ("frontend_web") is not allowed. To allow this host, add "frontend_web" to `server.allowedHosts` in vite.config.js.

I tried to use "vite-plugin-allowed-hosts" but it gives me an error when building the docker-container [ERROR] Failed to resolve entry for package "vite-plugin-allowed-hosts". The package may have incorrect main/module/exports specified in its package.json. [plugin externalize-deps]

Share Improve this question edited Jan 21 at 6:15 twentyxic asked Jan 20 at 18:29 twentyxictwentyxic 911 silver badge3 bronze badges 2
  • I had this pop up today as well, and saw your question. Seems like some recent releases are relevant to the server.allowedHosts feature: github.com/vitejs/vite/commit/… I rolled back to version 6.0.6 which gets my application back up and running. This doesn't "fix" the issue technically, but perhaps more information will come out soon on how to properly set this up in newer versions. – RealDealNeill Commented Jan 21 at 2:31
  • Thanks for the answer! It turned out that the dockerfile specified the line ``` RUN npm install -g vite``` without specifying the version, so the latest release was installed, which broke the application. I installed the version below – twentyxic Commented Jan 21 at 6:11
Add a comment  | 

1 Answer 1

Reset to default 8

A recent Vite update (6.0.11, to my knowledge) has introduced changes that "break" setups using proxies. To resolve this, you need to configure allowedHosts in your Vite configuration as told.

In your case this should work:

server: {
  allowedHosts: ['frontend_web'],
}

本文标签: reactjsBlocked request This host (quotfrontendwebquot) is not allowedStack Overflow