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

module is not defined #6

Open
gajus opened this issue Sep 1, 2019 · 6 comments
Open

module is not defined #6

gajus opened this issue Sep 1, 2019 · 6 comments

Comments

@gajus
Copy link

gajus commented Sep 1, 2019

After adding this plugin I am getting this error:

ReferenceError: module is not defined

Screenshot 2019-09-01 at 17 56 33

@gajus
Copy link
Author

gajus commented Sep 1, 2019

Somehow including import gql from 'graphql-tag'; is causing module to be undefined. I am puzzled.

@gajus
Copy link
Author

gajus commented Sep 1, 2019

haven't figured out what is the issue with how craco-plugin-react-hot-reload is patching CRA, but simply doing:

/* eslint-disable import/no-commonjs, filenames/match-regex, import/unambiguous, global-require */

module.exports = {
  webpack: {
    configure: (webpackConfig) => {
      webpackConfig.module.rules.push({
        test: /\.(js)$/,
        use: 'react-hot-loader/webpack',
        include: /node_modules/,
      });

      return webpackConfig;
    },
  },
};

works.

@TENsaga
Copy link

TENsaga commented Oct 2, 2019

haven't figured out what is the issue with how craco-plugin-react-hot-reload is patching CRA, but simply doing:

/* eslint-disable import/no-commonjs, filenames/match-regex, import/unambiguous, global-require */

module.exports = {
  webpack: {
    configure: (webpackConfig) => {
      webpackConfig.module.rules.push({
        test: /\.(js)$/,
        use: 'react-hot-loader/webpack',
        include: /node_modules/,
      });

      return webpackConfig;
    },
  },
};

works.

Thank you so much!! I've been struggling to get this working in IE 11 for awhile now and this was the ticket. All other browsers were working prior to the above, I've removed the Craco package and the webpack config code above resolved it.

@fridaystreet
Copy link

I was having this same issue and thanks @gajus your solution got me going again. I dug a bit further and found the cause of the problem.

This plugin adds the bable config for react-hot-loader and the webpack alias @hot-loader/react-dom. It should just be one or the other, preferably the latter and then you don't need to use the legacy way of enabling it you just use

import { hot } from 'react-hot-loader/root'

export default hot(App)

you can confirm this by just manually adding it to the craco.config.js, you don't even need the rest of the webpack stuff, well or this plugin I guess. Apologies @hasanayan don't mean to make it redundant, thanks for taking the time to do it in the first place.

module.exports = function({ env, paths }) {
  return {
    webpack: {
      alias: {
        'react-dom': '@hot-loader/react-dom',
      }
    }
  };
};

@riotrah
Copy link

riotrah commented Jul 30, 2020

@fridaystreet are you saying all you added to your craco config was the webpack alias and hot reloading works just like that?

@fridaystreet
Copy link

@riotrah yep that's right

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

No branches or pull requests

4 participants