Error AtlasError Documentation and Resolution

Vite built file failed because it was opened over the file protocol

Access to script at 'file:///foo/bar.js' from origin 'null' has been blocked by CORS policy

A built Vite app was opened directly from the filesystem, but browser security blocks module and asset loading over the `file://` protocol.

Access to script at 'file:///...' from origin 'null' has been blocked by CORS policyruntime
Access to script at 'file:///foo/bar.js' from origin 'null' has been blocked by CORS policy
  • The generated HTML was opened directly from the filesystem.
  • Browser same-origin rules block module loading from `file://` URLs.
  • The built app is being tested without an HTTP server.
  1. Serve the built app over HTTP instead of opening the HTML file directly.
  2. Use `vite preview` or another static server to test the production build.
  3. Avoid validating browser module behavior using the `file://` protocol.
Vite: Troubleshooting
Vite built file CORS error file protocol: causes and fixes | Error Atlas