Access to Script at ' from origin 'null' has been blocked by CORS policy | Sololearn: Learn to code for FREE!


Access to Script at ' from origin 'null' has been blocked by CORS policy

I was doing the modules lesson today in JavaScript course, so I wanted to play around with modules a little to understand them better, this error appears however and my modules don't work: Access to script at ' folder location.....' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https. How do I fix that?

11/27/2020 6:05:29 PM


2 Answers

New Answer


For security reasons, scripts that run on a browser may not make requests to the file system. You can start a Node server on your local machine. If you load the page with http or https protocol, EcmaScript modules will work. If you prefer to use the file:// protocol, you should consider transpiling your EcmaScript code with Babel to something compatible with most browsers.


A beginner's friendly way to fix that is to download the "bracket editor" and open your page using "live preview". This automatically create a server at the location and let's you practise module without stress. The difficult method is to buy a server or subscribe to their free plan, host your files and start working from there.