directory-named-webpack-plugin icon indicating copy to clipboard operation
directory-named-webpack-plugin copied to clipboard

Doesn't resolve when using HMR

Open fadilmamedov opened this issue 6 years ago • 4 comments
trafficstars

Let's say I have a folder in source folder named Component and two files inside it: index.js and Component.js. Configuration looks like so:

extensions: ['*', '.js', '.jsx', '.json'],
plugins: [
  new DirectoryNamedWebpackPlugin(true),
],

When I start Webpack everything works as expected, index.js file is loaded. But when I remove index.js file I expect Component.js to be loaded, but instead it still tries to load index.js file. It works as expected if I restart Webpack though. But I want this to be working correctly with Webpack Dev Server and HMR.

What am I doing wrong?

fadilmamedov avatar Jan 10 '19 22:01 fadilmamedov

Any updates on this?

fadilmamedov avatar Feb 07 '19 14:02 fadilmamedov

Sorry, somehow I missed this.

From what I understand, I think this is an issue of Webpack. I feel Webpack caches the resolved path for a given import path and doesn't use the resolver to resolve the path again with HMR.

shaketbaby avatar Sep 20 '19 19:09 shaketbaby

From what I understand, I think this is an issue of Webpack. I feel Webpack caches the resolved path for a given import path and doesn't use the resolver to resolve the path again with HMR.

Perhaps something as simple as delete require.cache[path]. Just an idea, we're not having the issue.

catamphetamine avatar Aug 03 '20 15:08 catamphetamine

Thanks for the idea. Actual require call is done by Webpack, this plugin only tells Webpack which file should be loaded for a given import/require. I didn't check the source code of Webpack but I suspect it probably is not using require as Node interpret things as JavaScript, but Webpack supports loading all kinds of things.

shaketbaby avatar Aug 05 '20 06:08 shaketbaby