laravel-mix: "Cannot GET /js/app.js" in HMR Mode

  • Laravel Mix Version: 2.0.0
  • Node Version (node -v): 8.9.4
  • NPM Version (npm -v): 5.6.0
  • Laravel Version: 5.6.3
  • OS: Windows 10

Description:

When I access http://localhost:8080/js/app.js in HMR mode (npm run hot), the server returns 404 with message: “Cannot GET /js/app.js”.

Steps To Reproduce:

  1. Create new laravel project by using laravel new <project_name> command
  2. Run npm install
  3. Delete public/js/app.js to avoid confusion. Assets are served from memory
  4. With browser, go to http://localhost:8080/js/app.js

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 19

Most upvoted comments

This is the workaround, inspired from #1437 :

Put this into webpack.mix.js.

Mix.listen('configReady', (webpackConfig) => {
  if (Mix.isUsing('hmr')) {
    // Remove leading '/' from entry keys
    webpackConfig.entry = Object.keys(webpackConfig.entry).reduce((entries, entry) => {
      entries[entry.replace(/^\//, '')] = webpackConfig.entry[entry];
      return entries;
    }, {});

    // Remove leading '/' from ExtractTextPlugin instances
    webpackConfig.plugins.forEach((plugin) => {
      if (plugin.constructor.name === 'ExtractTextPlugin') {
        plugin.filename = plugin.filename.replace(/^\//, '');
      }
    });
  }
});

I’m using laravel’s react scaffolding and this doesn’t fix the issue for me

@nkrh

I think this doesn’t fix hot-reloading of css though.

Stil broken in the latest stable laravel/laravel release; when will a fix (this fix?) ship?

The proposed fix works but this is a workaround. All users using windows have this problem i’m still waiting for an official fix. There are many issues regarding this since v2.0.0

@JeffreyWay do you plan to apply some of the proposed solutions or we should use them this way ?