Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser Sync won't load bundle.js on external devices for dev build #205

Closed
SunnyJohal opened this issue Jul 18, 2016 · 23 comments
Closed
Labels

Comments

@SunnyJohal
Copy link

SunnyJohal commented Jul 18, 2016

Node version: 6.2.2

npm version: 3.9.5

Operating system: MAC OSX El Capitan (v 10.11.15)

Command line used: npm start -s

Steps to reproduce:

  • Npm install the starter kit
  • Run the command in dev mode: npm start -s
  • Once the app is loaded locally: On an external device enter the External access URL in the browser.
  • Open the browser console, you will see the error message: http://localhost:3000/bundle.js net::ERR_CONNECTION_REFUSED

What I've tried:

  • Using a different port for the app (no success).
  • Trying a different external device (another laptop and phone, no luck).
  • Using a different machine to run the app on (another mac, no luck).

Note:

Browser sync hot reloading works fine with the production build. It's the development environment that I appear to be having issues with .

Really love this starter kit and want to use it so hope it's an issue that I can get resolved. Cheers

Sunny

@coryhouse coryhouse changed the title Browser Sync not loading bundle.js on external devices Browser Sync not loading bundle.js on external devices for dev build Jul 18, 2016
@coryhouse coryhouse added the bug label Jul 18, 2016
@kwelch
Copy link
Collaborator

kwelch commented Jul 18, 2016

Does the external address work at all? If you use it on the local device with the external address does it load?

@SunnyJohal
Copy link
Author

Yes the external address works on my local device. Thanks for your response.

@coryhouse
Copy link
Owner

This is interesting timing because I was considering removing browsersync since it complicates configuration and I suspect few are using its sync features.

That said, great catch. I've reproduced the issue. I don't have a fix idea at this point, but thanks for the heads up.

@coryhouse coryhouse changed the title Browser Sync not loading bundle.js on external devices for dev build Browser Sync won't load bundle.js on external devices for dev build Jul 18, 2016
@SunnyJohal
Copy link
Author

I have a feeling that it is something to do with the webpack-dev-middleware package. I'll let you know if I find a fix for this issue. Cheers

@SunnyJohal
Copy link
Author

Ok when I edit the publicPath property in webpack.config.dev.js to use the ip address on my local machine (in place of localhost) then hot reloading works. Not ideal but a temporary fix for anyone reading this issue.

@coryhouse
Copy link
Owner

Yep, you're on the right track. That's where I was focused as well. I hoped removing the publicPath altogether would resolve it, but that didn't fix it for me.

It does appear we don't need publicPath anymore. I could have sworn it was necessary before.

@SunnyJohal
Copy link
Author

An even better fix is to simply comment out the publicPath property in webpack.config.js

@coryhouse
Copy link
Owner

Ah, indeed! Problem is, the public path was added to resolve this issue in dev: #125

Any ideas on how to support both use cases?

@SunnyJohal
Copy link
Author

A possible solution could be to change the publicPath line to read publicPath: '/' (just an idea it would need testing). How can I reproduce the error in #125 ?

@SunnyJohal
Copy link
Author

I'm not getting this error when I leave out the public path. Is it still an issue? Are you able to test this locally?

@coryhouse
Copy link
Owner

"I'm not getting this error..."

Which error are you referring to?

@SunnyJohal
Copy link
Author

I am able to load webfonts without any issues.

@SunnyJohal
Copy link
Author

Ignore that last post I can see the blob: prefix on the url now. I'll look into this further

@SunnyJohal
Copy link
Author

SunnyJohal commented Jul 18, 2016

There needs to be a way to get the ip address dynamically using node. Do you know of an easy way to do this?

@kwelch
Copy link
Collaborator

kwelch commented Jul 19, 2016

We should be able to pull this off with the process.env object. As you would expect the properties are IP and port.

@SunnyJohal
Copy link
Author

Hi ketch,
I'm getting undefined when I'm trying to access process.env.IP did you have any luck? Am I referencing that property correctly?

@SunnyJohal
Copy link
Author

*kwelch

@SunnyJohal
Copy link
Author

Ok so I've figured out a work around to fetch the ip address dynamically for now (based on this post)

So after line 3 in webpack.config.dev.js I add the following code to get the ipAddress

const os = require('os');
const ifaces = os.networkInterfaces();

let lookupIpAddress = null;

for ( let dev in ifaces ) {
  if ( dev !== 'en1' && dev !== 'en0' ) {
    continue;
  }

  ifaces[ dev ].forEach( function( details ) {
    if ( details.family === 'IPv4' ) {
      lookupIpAddress = details.address;
    }
  });
}

let ipAddress   = lookupIpAddress;

Then I replace the line publicPath: 'http://localhost:3000/', with publicPath: 'http://' + ipAddress + ':3000/'

If there is a more succinct way of getting the same result I'd love to hear it.

@kwelch
Copy link
Collaborator

kwelch commented Jul 19, 2016

They may be undefined, I typically use those variables with fallbacks. I should have some time tonight to crack this open and take a look. I know that I have given demos using Browsersync on external devices.

@SunnyJohal
Copy link
Author

Awesome, I look forward to seeing what you come up with!

@kwelch
Copy link
Collaborator

kwelch commented Jul 20, 2016

Please see comment on #125, I did my best to go into detail on what I was seeing and why.

@kwelch
Copy link
Collaborator

kwelch commented Jul 22, 2016

This can be closed with that PR merge.

@coryhouse
Copy link
Owner

Thanks for the heads up @kwelch! Thanks to @kwelch for resolving!

PR: #207

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants