1

enter image description here

When I add a spline 3d element in javascript I have to use module to use it and then I get that error it says ccess to script at 'file:///D:/js%20learn/spline.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.

Please help me. I need to use that spline 3d element

I tried to upload that javascript file on a server to use it as an http link but I don't know how

1
  • 2
    Annoying as it is for web development, you will need to run a local server to serve files and prevent these 'origin' issues. These are there to prevent sites from accessing files and folders on your computer. The easiest way I know is to install NodeJS, then in terminal install a global http server with npm install http-server -g. After that, open your folder in terminal and run http-server and you should be ready to start development while avoiding any protocol, origin and file issues. Commented Dec 31, 2022 at 9:52

1 Answer 1

3

You will need a web server to serve over the http protocol. For development you can use a localhost. The easiest way I know how to do that is to install NodeJS on your system. Then open a terminal or command line prompt (I think on windows this is run) and install the server stuff by running this command:

npm install http-server -g

Now drag the root folder of your project into the terminal to go to that folder (or somehow get to that folder, if you are on Windows I can't exactly tell you). From that location, run this command:

http-server

It will log a bunch a things, but most importantly it will allow you to visit your project as if it was a website on a server. It's usually located in the localhost domain, like localhost:8080. This should prevent any CORS/origin/protocol issues in general (there are some other cors issues you could run into but deal with those when you get to them).

There are also solutions that don't require you to use a terminal at all like MAMP. Point it at your folder and start a server. But if you are going to continue in web development, making yourself familiar with terminal and command line will be a boon.

Not the answer you're looking for? Browse other questions tagged or ask your own question.