Skip to content

Commit f15debc

Browse files
sapphi-redpull[bot]
authored andcommitted
docs: add trouble shooting section about file protocol (#10231)
1 parent 27ff771 commit f15debc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/guide/troubleshooting.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ If HMR is not handled by Vite or a plugin, a full reload will happen.
7676

7777
Also if there is a dependency loop, a full reload will happen. To solve this, try removing the loop.
7878

79+
## Build
80+
81+
### Built file does not work because of CORS error
82+
83+
If the HTML file output was opened with `file` protocol, the scripts won't run with the following error.
84+
85+
> Access to script at 'file:///foo/bar.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
86+
87+
> Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///foo/bar.js. (Reason: CORS request not http).
88+
89+
See [Reason: CORS request not HTTP - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSRequestNotHttp) for more information about why this happens.
90+
91+
You will need to access the file with `http` protocol. The easiest way to achieve this is to run `npx vite preview`.
92+
7993
## Others
8094

8195
### Syntax Error / Type Error happens

0 commit comments

Comments
 (0)