I got this error while trying to launch an html page using a javascript file which imported a function from another file:
Access to script at 'file:///C:/Users/bla/Desktop/stuff/practice/jsPractice/funcexecute.js'
from origin 'null' has been blocked by CORS policy:
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
Failed to load resource: net::ERR_FAILED
Here's the html code:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
<script type = 'module' src='funcexecute.js'></script>
</body>
</html>
js file which was called from the html: (funcexecute.js)
import sumup from '/funcfile.js';
console.log(sumup(1,2));
Imported module: (funcfile.js)
function sumup(num1, num2){
return num1+num2;
}
export default sumup;
How can i fix this? (im using vscode)
file:///
. Either use a remote server, or set up a local one, it's easy these days, with NodeJS and Express for example. You'll then be able to access your files usinglocalhost
– Cabala