From f15debcd0c6c8f1fa50b9b7150210804fb2acca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sat, 24 Sep 2022 23:10:33 +0900 Subject: [PATCH] docs: add trouble shooting section about file protocol (#10231) --- docs/guide/troubleshooting.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index 4fb826a3ee85b9..d57899be3112d3 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -76,6 +76,20 @@ If HMR is not handled by Vite or a plugin, a full reload will happen. Also if there is a dependency loop, a full reload will happen. To solve this, try removing the loop. +## Build + +### Built file does not work because of CORS error + +If the HTML file output was opened with `file` protocol, the scripts won't run with the following error. + +> 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. + +> Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///foo/bar.js. (Reason: CORS request not http). + +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. + +You will need to access the file with `http` protocol. The easiest way to achieve this is to run `npx vite preview`. + ## Others ### Syntax Error / Type Error happens