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

HMR / dev-server is not working inside a VM despite the documentation #277

Closed
tristanbes opened this issue Mar 6, 2018 · 6 comments
Closed
Labels

Comments

@tristanbes
Copy link

tristanbes commented Mar 6, 2018

Hello,

We're facing a problem while trying to run HMR:

building with

/node_modules/.bin/encore dev-server --host 0.0.0.0 --port 8000 --disable-host-check --hot --public enigma.vm

accessing http://enigma.vm/login, the assets are trying to load from http://0.0.0.0:8000/build/login.css
but the local traffic is redirected on enigma.vm. so http://0.0.0.0:8000 does not answer.
yet, http://enigma.vm:8000/build/home.css serve the right asset.

When trying something different:

./node_modules/.bin/encore dev-server --host enigma.vm --port 8000 --disable-host-check --hot

The assets is correctly served from the server http://enigma.vm:8000/build/home.css

But when trying to access http://enigma.vm/login, then the assets are loaded from http://enigma.vm:8000/build/login.css which reply with net::ERR_CONNECTION_REFUSED

My frontend dev is 100% blaming webpack-encore, and say this would never happened running webpack without the wrapper. I'm sad because I was an advocate to encore.... help me prove him wrong ;-)

const Encore = require('@symfony/webpack-encore');

Encore
  .setOutputPath('public/build/')
  .setPublicPath('/build')
  .cleanupOutputBeforeBuild()
  .enableSourceMaps(!Encore.isProduction())
  .enableVersioning(Encore.isProduction())

  .addEntry('home', './assets/js/home/home.js')
  .addEntry('login', './assets/js/login/login.js')
  .enableVueLoader()
;

var config = Encore.getWebpackConfig();
config.watchOptions = { poll: 300, ignored: /node_modules/ };

module.exports = config;

PS i've read #126 thought it would help me, but it's not :(

@Lyrkan
Copy link
Collaborator

Lyrkan commented Mar 6, 2018

Hi @tristanbes,

There was another issue about using --host 0.0.0.0 that may be relevant to your case: #59

The PR that fixed it (#96) made it possible to use an URL when calling setPublicPath(), maybe you could try doing that?

It was also supposed to add a --keep-public-path option to avoid adding the 'host' part to the public path but sadly it doesn't seem to be working anymore (see #180, that behavior could probably be reproduced by replacing the path where it appears in the generated config though).

@Lyrkan Lyrkan added the question label Mar 6, 2018
@MGatou
Copy link

MGatou commented Mar 13, 2018

The PR #96 fixes the problem.

  • In my webpack.conf.js, I add this config :
// .. rest of configuration
if (!Encore.isProduction()) {
  Encore
    .setPublicPath('http://enigma.vm:8080/build/')
    .setManifestKeyPrefix('build/')
  ;
}
  • And I also add the options --host 0.0.0.0 --disable-host-check to my dev-server

Thanks @Lyrkan

@weaverryan
Copy link
Member

Is there some documentation we can update to help make this easier?

@tristanbes
Copy link
Author

@ELFrontEnd
Copy link

I'm sorry but i can't get it to work properly with this confg with a docker and symfony 3.4.

  • Url: http://mysite.com:3477/

  • package.json script:
    "build-local": "encore dev-server --host 0.0.0.0 --disable-host-check --hot", "build-serverside": "encore dev --config webpack.config.serverside.js --watch", "build": "run-p build-local build-serverside"

  • webpack.config.js:

const Encore = require('@symfony/webpack-encore'); Encore .setOutputPath('web/build/') .setPublicPath('/build') .cleanupOutputBeforeBuild() .addEntry('app', ['babel-polyfill', './app/Resources/js/entryPoint.js']) .autoProvidejQuery() .enableVersioning(Encore.isProduction()) .enableSourceMaps(!Encore.isProduction()); if (!Encore.isProduction()) { Encore .setPublicPath('http://mysite:3477/build') .setManifestKeyPrefix('build/'); } const config = Encore.getWebpackConfig(); // config.watchOptions = { poll: 300, ignored: /node_modules/ }; module.exports = config;

And in twig file:
{% block javascripts %} <script src="{{ asset('build/app.js') }}"></script> {% endblock %}

I keep getting connection reset or 404 errors and i can't find a proper docker configuration.

@Kocal
Copy link
Contributor

Kocal commented Apr 13, 2019

I've just opened symfony/symfony-docs#11422 that should help

javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Apr 25, 2019
…cal)

This PR was squashed before being merged into the 3.4 branch (closes #11422).

Discussion
----------

Encore: add guide to use Encore in a virtual machine

Hi, ✋

As the title says, this PR add a new guide for using Encore in a virtual machine.

This is what we use on ours Symfony apps at work which run inside a Vagrant VM.
It works really fine and I thought it would be helpful to share it with other people.

Also, I've removed a sub-section in the actual doc because according to symfony/webpack-encore#277, it was not working because some additional configuration was missing (and I can confirm it because I'm one of his co-worker 😛).

Commits
-------

86c897f Encore: add guide to use Encore in a virtual machine
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

6 participants