verekia / js-stack-from-scratch

🛠️⚡ Step-by-step tutorial to build a modern JavaScript stack.
MIT License
20.09k stars 1.99k forks source link

HMR failling because of Access-Control-Allow-Origin #207

Closed iamandrewluca closed 7 years ago

iamandrewluca commented 7 years ago

Type of issue: bug

Chapter: 4 after adding HMR

If it's a bug:

[WDS] App updated. Recompiling...
[WDS] App hot update...
[HMR] Checking for updates on the server...
XMLHttpRequest cannot load http://localhost:7000/dist/ffacf69653bfa6a58a17.hot-update.json.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8000' is therefore not allowed access.

Fix:

Add to webpack.config.babel.js

devServer: {
  // ...
  headers: { 'Access-Control-Allow-Origin': '*' }
}

image

samgranieri commented 7 years ago

This worked for me

iamandrewluca commented 7 years ago

Maybe is related to browser environment. I will add in the evening more info

iamandrewluca commented 7 years ago

I don't know why this happened. Now I can't reproduce this problem.

iamandrewluca commented 7 years ago

Sorry for reopening. I will close it for now.

umaulana commented 7 years ago

I encountered same issue

Myoursky commented 7 years ago

I encountered same issue,but with the official code ,I can't reproduce this problem.

verekia commented 7 years ago

It is likely due to a more recent of Webpack Dev Server than the one I used in the walkthrough. I will update the tutorial asap. Sorry about that!

zcntpz commented 7 years ago

webpack.config.babel.js add devServer: { headers: { 'Access-Control-Allow-Origin': 'http://localhost:8000' } } to fix

crisisdesign commented 7 years ago

a better aproach could be import the web port from "./src/shared/config":

import { WDS_PORT, WEB_PORT } from './src/shared/config' // [...] devServer: { headers: { 'Access-Control-Allow-Origin': http://localhost:${WEB_PORT} }, },

JiangdandanAbigale commented 7 years ago

thanks.

lavebug commented 7 years ago

headers: { 'Access-Control-Allow-Origin': '*' } in webpack.config.babel.js worked. Thanks

verekia commented 7 years ago

It's fixed in the latest version of the tutorial. Thanks everyone :)

jerryOnlyZRJ commented 5 years ago

Thank you! It works for me! 🎉