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

后端 未结 2 1551
孤城傲影
孤城傲影 2020-12-30 19:31

So when I am trying to import class from another javascript file, I am getting error in console like this:

Access to Script at \'file:///home/../.../JavaScri         


        
相关标签:
2条回答
  • 2020-12-30 20:15

    ES6 modules are subject to same-origin policy. You need to run your script from a local server, open directly the file with a browser will not work.

    see here ES6 module support in Chrome 62/Chrome Canary 64, does not work locally, CORS error

    0 讨论(0)
  • 2020-12-30 20:16

    file:// requests will not work, but you can run a local webserver (polymer serve, express, etc.) to use HTTP requests instead. You could even use the following Chrome extension to run a local webserver.

    https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb?hl=en

    0 讨论(0)
提交回复
热议问题