Home [Html] from origin 'null' has been blocked by CORS policy 에러발생
Post
Cancel

[Html] from origin 'null' has been blocked by CORS policy 에러발생


에러 발생

from origin 'null' has been blocked by CORS policy 에러발생 index.html 파일을 Open In Default Browser(Alt+B)로 실행하니 index.js를 불러오려고 하는 부분에서 위와 같은 Error가 발생했다.

해결방법

1. http-server가 설치돼 있지 않다면

1
npm install http-server -g

2. http-server 실행

1
npx http-server

위 코드를 터미널에 입력하고 엔터를 치면 아래와 같은 결과가 뜬다.

npx http-server

그럼 주소가 2개 뜨는데 하나 골라서 주소창에 입력하고 들어가면 에러 없이 index.html 파일을 로컬에 실행시킬 수 있다.


마치며

혹시 잘못된 정보나 궁금하신 게 있다면 편하게 댓글 달아주세요.
지적이나 피드백은 언제나 환영입니다.

This post is licensed under CC BY 4.0 by the author.