Skip to content

aspnet-webpack-react not compatible with react-hot-loader v4 #5178

Description

@Guymestef

Hello,

react-hot-loader/patch has been removed from react-hot-loader v4: See documentation here

A new package for aspnet-webpack-react (v4.0.0?), removing support of "reactHotLoaderPatch", need to be created I suppose.

To remove?

const reactHotLoaderPatch = 'react-hot-loader/patch';

To remove?

        let entryValueArray = entryConfig[entrypointName] as string[];
        if (entryValueArray.indexOf(reactHotLoaderPatch) < 0) {
            entryValueArray.unshift(reactHotLoaderPatch);
        }

react-hot-loader release note

Activity

  1. Guymestef commented on Mar 21, 2018

    @Guymestef
    Author

    For users still using react-hot-loader v3, they would be able to use this new version by adding react-hot-loader/patch to their webpack conf manually. No?

  2. Guymestef commented on Mar 21, 2018

    @Guymestef
    Author

    By doing some test, it seems that the module react-hot-loader/webpack has been removed too...

    const reactHotLoaderWebpackLoader = 'react-hot-loader/webpack';
  3. mark-monteiro commented on Mar 22, 2018

    @mark-monteiro

    The safest solution to this might be to check if the react-hot-loader/patch or react-hot-loader/webpack packages exist before injecting them into the webpack config. Then we won't break compatibility with v3. Would something like this work?

    function npmModuleIsPresent(moduleName: string) {
        try {
            require.resolve(moduleName);
            return true;
        } catch (ex) {
            return false;
        }
    }
    
  4. SteveSandersonMS commented on Mar 23, 2018

    @SteveSandersonMS
    Member

    Would something like this work?

    It looks like it would avoid the initial exception, but I'm not sure it solves the issue that HMR wouldn't work. Do you have an idea about how that should be changed for v4?

  5. mark-monteiro commented on Mar 23, 2018

    @mark-monteiro

    In the migration instructions for migrating from v3 to v4, the only mention of changes to webpack config is the removal of react-hot-loader/patch: https://github.com/gaearon/react-hot-loader#migrating-from-v3

    There is also a working example setup for HMR with Typescript that can be referenced: https://github.com/gaearon/react-hot-loader/tree/master/examples/typescript

    The only notable thing in that sample Webpack config is adding babel-loader before the Typescript loader which I think we are already doing: https://github.com/aspnet/JavaScriptServices/blob/02beb11a5c1a0f5a32e2345b0708a323c166627e/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts#L116

  6. rydergillen-compacSort commented on Mar 28, 2018

    @rydergillen-compacSort

    @SteveSanderson

    It looks like it would avoid the initial exception, but I'm not sure it solves the issue that HMR wouldn't work. Do you have an idea about how that should be changed for v4?

    I would like to add that by removing the following lines (along with usage of variables) from HotModuleReplacement.ts I was able to successfully use webpack 4 & HMR inside of the ASPNET CORE React/Redux template site.

    var reactHotLoaderWebpackLoader = 'react-hot-loader/webpack';
    var reactHotLoaderPatch = 'react-hot-loader/patch';
    

    If thats the case then @mark-monteiro suggestion of conditionally invoking may just work. Can anyone else confirm this resolves their issue?

  7. reecreatepatrik commented on Mar 28, 2018

    @reecreatepatrik

    It resolved it for me too.

  8. mark-monteiro commented on Mar 28, 2018

    @mark-monteiro

    When I tested the change it also worked for me as well, but I didn't want to comment on that because I ran through it very briefly and didn't test anything very thoroughly.

    That being said, is it fair to say that this would be a good change to make regardless of the status of compatibility with v4? It seems like a prudent measure to make sure a package is installed before trying to use it.

    If we make this change then we maintain backwards compatibility without totally breaking people's builds when they try to update to v4 as is the case now. If there is any further configuration changes required for v4 compatibility, then at least there will be the option to make those Webpack config changes manually.

  9. Tsourdox commented on Apr 26, 2018

    @Tsourdox

    Has the change been implemented yet? If not, where would be the proper place to add/call the "npmModuleIsPresent" function?

  10. Tsourdox commented on Apr 26, 2018

    @Tsourdox

    Tried @rydergillen-compacSort solution, worked for me too!

  11. Tsourdox commented on May 10, 2018

    @Tsourdox

    Any updates on this issue? 🙏

  12. feafarot commented on May 29, 2018

    @feafarot

    Since #1562 was resolved. Maybe this issue also could now be fixed?

  13. tjaskula commented on Jun 6, 2018

    @tjaskula
    Contributor

    any solution doesn't work for me. Would be good to release a new version compatible with react-hot-loader v4

  14. cvanem commented on Jun 23, 2018

    @cvanem

    @SteveSandersonMS I hate to bug you, but would it be possible to get this PR merged, assuming there is nothing holding it up? We have been waiting a while and it would be nice to be able to upgrade. The proposed solution works for myself and others as described above. Is there anything holding this up?

  15. TimeWanderer commented on Aug 1, 2018

    @TimeWanderer

    Any updates on this?

  16. tjaskula commented on Aug 1, 2018

    @tjaskula
    Contributor

    Waiting for #1675 being merged

  17. GGAlanSmithee commented on Oct 30, 2018

    @GGAlanSmithee

    Seems like this is now fixed, and is working for me aspnet/JavaScriptServices#1675 (comment)

  18. added
    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
    on Dec 17, 2018
  19. mkArtakMSFT commented on Jan 17, 2019

    @mkArtakMSFT
    Contributor

    Closing as this seems to be resolved now.

  20. ghost locked as resolved and limited conversation to collaborators on Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-spa

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions