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

Webpack Hot Dev Client Breaks on older browsers #5336

Closed
cliedeman opened this issue Oct 7, 2018 · 44 comments
Closed

Webpack Hot Dev Client Breaks on older browsers #5336

cliedeman opened this issue Oct 7, 2018 · 44 comments
Milestone

Comments

@cliedeman
Copy link

Is this a bug report?

yes

Did you try recovering your dependencies?

no

Which terms did you search for in User Guide?

hot dev

Environment

System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Binaries:
Node: 8.12.0 - /usr/local/opt/node@8/bin/node
Yarn: 1.10.1 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/opt/node@8/bin/npm
Browsers:
Chrome: 69.0.3497.100
Safari: 12.0
npmPackages:
react: ^16.5.2 => 16.5.2
react-dom: ^16.5.2 => 16.5.2
react-scripts: 2.0.4 => 2.0.4
npmGlobalPackages:
create-react-app: 2.0.0-next.2150693d

Steps to Reproduce

(Write your steps here:)

  1. npx create-react-app my-app
  2. cd my-app
  3. yarn start
  4. Navigate to app url in old browser that does not have map. E.g. Android 4.4 default browser or ie9 (I used Android 4.4)

Expected Behavior

Default Screen Loads

Actual Behavior

Blank Screen, connecting the debugger reveals the console error Map is not defined

This is caused by a Map call from ansi-styles which is required by chalk.

screen shot 2018-10-07 at 02 00 09

To get past this I added require('react-app-polyfill/ie9'); to the top of webpackHotDevClient (Delete the babel loader cache if you do this). This gets further but then failes on setPrototypeOf. Using the catch all require('core-js'); allows the app to work as expected.

screen shot 2018-10-07 at 02 02 21

Note: the yarn build version always works because the hot dev client is not present

I am not sure if this is something CRA actually wants to support, I think some documentation that the dev mode yarn start may not work with older browsers will be enough.

@ematipico
Copy link

CRA doesn't support old browsers anymore by default. https://reactjs.org/blog/2018/10/01/create-react-app-v2.html#breaking-changes

@cliedeman
Copy link
Author

But I still expected it to work after adding the opt in polyfills

@ematipico
Copy link

Try to use the latest of CRA. I see that you using a next branch, not sure if it's up to date or not...

@Timer Timer added this to the 2.0.x milestone Oct 14, 2018
@miraage
Copy link

miraage commented Oct 29, 2018

@cliedeman do you have import 'react-app-polyfill/ie9'; as the very first line of src/index.js?

@lomocc
Copy link

lomocc commented Nov 29, 2018

I found the dependencies cause the bug

create-react-app -> react-scripts/config/webpack.config.js -> react-dev-utils/webpackHotDevClient.js -> react-dev-utils/formatWebpackMessages.js -> chalk -> ansi-styles -> Map

and I think we need setupPolyfill ( just like setupProxy),it should be insert before webpackHotDevClient:

entry: [
  paths.setupPolyfill,
  isEnvDevelopment &&
  require.resolve('react-dev-utils/webpackHotDevClient'),
  // Finally, this is your app's code:
  paths.appIndexJs,
]

@weiq
Copy link

weiq commented Jan 25, 2019

@iansu iansu modified the milestones: 2.1.x, 3.x Mar 10, 2019
@Nickman87
Copy link

Having the same issue trying to debug my app on IOS 7 safari.
Is there a workaround for this?

@lomocc
Copy link

lomocc commented Mar 15, 2019

@Nickman87

My temp solution, put this in public/index.html

<% if (process.env.NODE_ENV === 'development') { %>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.5/es6-sham.min.js"></script>
<% } %>

https://gist.github.com/lomocc/a73ec03d7d01a319098ee90165f74c24

@arnaudambro
Copy link

Thanks to @lomocc comment, I sorted it out that way: I added a paths.setupPolyfill in ./config/webpack.config.js like he said:

entry: [
  paths.setupPolyfill,
  isEnvDevelopment &&
  require.resolve('react-dev-utils/webpackHotDevClient'),
  // Finally, this is your app's code:
  paths.appIndexJs,
]

and then in the ./config/paths.js I added and export:

module.exports = {
  //  ... all the exports
  appNodeModules: resolveApp('node_modules'),
  setupPolyfill: resolveApp('node_modules/react-app-polyfill/ie9'), // added
};

I also needed the es6-sham.min.js script to make it work, so in my index.html I added these lines:

<% if (process.env.NODE_ENV === 'development') { %>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.5/es6-sham.min.js"></script>
<% } %>

@shirakaba
Copy link

shirakaba commented Jul 3, 2019

Solution in my case

Thanks to @lomocc and @arnaudambro for their work on this.

If you want to get the dev build working without altering react-scripts/config.webpack.js and react-scripts/config/paths.js, adding this before my closing </body> tag in index.html worked for me (when trying to support Opera 12.16):

<% if (process.env.NODE_ENV === 'development') { %>
  <script src="https://polyfill.io/v3/polyfill.min.js?features=Map%2CSet%2CObject.setPrototypeOf"></script>
<% } %>

Note that I'm not using es6-sham here. I'm (potentially redundantly) providing polyfills.

Details

How I determined which features were missing

I was specifically trying to enable an app to run in Opera 12.16, which I initially found lacked Map support. So I started by providing a polyfill for that using polyfill.io's URL builder. But then I found it still lacked Set. So one-by-one, I polyfilled each lacking feature that the browser was failing on, and concluded that for Opera 12.16, I needed to polyfill Map, Set, and Object.setPrototypeOf to support the DevTools.

Polyfill redundancy in dev mode

If you're polyfilling anything from react-app-polyfill in index.js, you may now be polyfilling some of the same features again redundantly (purely to provide them in time for the DevTools to use them). In the production build though, neither DevTools nor my above polyfill will be included, so it's a moot point.

@seanbecker15
Copy link

seanbecker15 commented Jul 12, 2019

IE 10 Compatibility

.NET Core / React / Redux

I just spent a few hours making my .NET Core / React app compatible with IE 10. Here is my solution until this is fixed in create-react-app. The above comments did not discuss MutationObserver, which is what caused me issues after ejecting and changing the order of dependencies.

  1. Eject create-react-app: npm run eject
    • Before doing this you should read about ejecting, you can't turn back once you do.
  2. Change order of appIndexJs and webpackHotDevClient in config/webpack.config.js
  3. Add core-js & mutation-observer: npm install core-js mutation-observer
  4. Modify package.json with browserslist (ie > 9 is what is important here)
"browserslist": [
    "ie > 9",
    "last 1 chrome version",
    "last 1 firefox version",
    "last 1 safari version"
  ],
  1. Modify index.js
    • important: make sure that these go at the very top of index.js
    • Add polyfills, core-js, and mutation-observer
import 'core-js/es';
import 'react-app-polyfill/ie9';
import 'mutation-observer';

@shirakaba
Copy link

Eject create-react-app

@seanbecker15 Just to mention that you can avoid ejecting by using customize-cra or rescripts (they're both about equally as good) and re-ordering the webpack config as you require.

@NixBiks
Copy link

NixBiks commented Sep 30, 2019

Eject create-react-app

@seanbecker15 Just to mention that you can avoid ejecting by using customize-cra or rescripts (they're both about equally as good) and re-ordering the webpack config as you require.

Do you mind adding how?

@ThekhoN
Copy link

ThekhoN commented Oct 8, 2019

You do NOT have to eject from CRA.

Example: https://github.com/ThekhoN/create-react-app-ie11

Steps:

  1. Install react-app-polyfill

    npm i react-app-polyfill

  2. Import react-app-polyfill/ie11 at the TOP of index.js

    import 'react-app-polyfill/ie11'

3. Delete .cache in /node_modules

4. Add ie11 meta tag in index.html (in public folder)

<meta http-equiv="X-UA-Compatible" content="IE=11">

@activebiz
Copy link

@ThekhoN Your solution doesnt work for me. Clone your repo. it gives me following error with blank page on IE11.

SCRIPT1002: Syntax error
0.chunk.js (15,34)
SCRIPT1002: Syntax error
main.chunk.js (280,62)

@ThekhoN
Copy link

ThekhoN commented Oct 9, 2019

@activebiz can u try again.
I updated the repo by adding "IE 11" in the browserslist.

There seems to be some caching issue happening at IE11's end.
Try clearing the IE11 browser cache.
Running npm cache clean --force also seems to resolve the issue.

@nicoladl
Copy link

nicoladl commented Nov 8, 2019

@ThekhoN
you should also include import 'react-app-polyfill/stable' in according with the doc:
https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md

@ianschmitz ianschmitz modified the milestones: 3.3, 3.4 Dec 5, 2019
@jozsi
Copy link

jozsi commented Dec 26, 2019

@kareemali-afs, a couple of observations:

  • you don't need to install chalk react-dev-utils strip-ansi ansi-styles explicitly (I don't think you should even delete node_modules before)
  • make sure to update your package.json like this (otherwise the override won't have any effect, cause it will call the unmodified react-scripts):
  "scripts": {
    "start": "react-app-rewired start",

@kareemali-afs
Copy link

kareemali-afs commented Dec 26, 2019

@jozsi

  • True, I just do it to make sure it's clean from any changes I may have done while testing other solutions
  • I did add that but forgot to mention it my previous comment

You're probably right that it's because webpackHotDevClient loads first since the console error refers to this file but I am not sure why your solution is not working.

@jozsi
Copy link

jozsi commented Dec 26, 2019

@kareemali-afs - I published the repo with the craco config I made for @rjcnd105, take a look at the changes I've made. It works for the very old, embedded browser I use (same WebKit engine as PhantomJS 2.1 uses, with capabilities similar to Safari 6). I attempted to add IE 11 support, however, I did not test it (don't have an environment for it). Give it a try :)

@suminas85
Copy link

@kareemali-afs
As a temporary solution to debug in IE you can disable webpackHotDevClient

  • Add debug mode to scripts
  "scripts": {
    "start": "react-app-rewired start",
    "start:debug": "DEBUG_MODE=true react-app-rewired start",
  • update config-overrides.js :
const {
  override,
  babelInclude,
} = require('customize-cra');
const path = require('path');

module.exports = override(
  (config) => {
    if (process.env.DEBUG_MODE) {
      config.entry.shift(); // remove webpackHotDevClient (first as default)
      config.entry.unshift(require.resolve('react-app-polyfill/stable'));
    }

    return config;
  },
  babelInclude([path.resolve('src')])
);

@RickeyWard
Copy link

Create a new create-react-app, add react-app-polyfill, update index.js to include the pollyfills, update browserlist to have ie 11 in both prod and dev, and it works in build, but fails in dev, because of the websocket. Workarounds presented here haven't worked for me. I've been having to test changes by doing builds and static serving.

@PrajwalVBharadwaj
Copy link

None of the workarounds mentioned worked for me in development mode. Any updates about it?

@ivanmccarthy
Copy link

ivanmccarthy commented Jan 20, 2020

Create a new create-react-app, add react-app-polyfill, update index.js to include the pollyfills, update browserlist to have ie 11 in both prod and dev, and it works in build, but fails in dev, because of the websocket. Workarounds presented here haven't worked for me. I've been having to test changes by doing builds and static serving.

@RickeyWard Have you resolved this issue yet? I'm having the same problem.

@a1g0rithm
Copy link

I finally have a workaround after looking at this for a couple of days

I had to change the client for WebpackDevServer from react-dev-utils/webpackHotDevClient to the alternative of webpack/hot/dev-server

You have to go to your webpack.config.js file and swap out this line:

isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient'),

with this one:

isEnvDevelopment && require.resolve('webpack/hot/dev-server'),

@ivanmccarthy
Copy link

I finally have a workaround after looking at this for a couple of days

I had to change the client for WebpackDevServer from react-dev-utils/webpackHotDevClient to the alternative of webpack/hot/dev-server

You have to go to your webpack.config.js file and swap out this line:

isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient'),

with this one:

isEnvDevelopment && require.resolve('webpack/hot/dev-server'),

@a1g0rithm This worked for me, thank you very much.

@Felix-Indoing
Copy link

I downgrade CRA to 3.2.0 to make it work.

@strongui
Copy link

I finally have a workaround after looking at this for a couple of days

I had to change the client for WebpackDevServer from react-dev-utils/webpackHotDevClient to the alternative of webpack/hot/dev-server

You have to go to your webpack.config.js file and swap out this line:

isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient'),

with this one:

isEnvDevelopment && require.resolve('webpack/hot/dev-server'),

Did you have to do anything else? Because while this works to load up the page in IE, hot reload no longer works. You have to refresh the page manually to see the changes.

@a1g0rithm
Copy link

Did you have to do anything else? Because while this works to load up the page in IE, hot reload no longer works. You have to refresh the page manually to see the changes.

Unfortunately, hot reloading won't work. Not sure if downgrading like @Felix-Indoing suggests keeps it from breaking.

@daruj
Copy link

daruj commented Aug 4, 2020

Hey, I'm having the same issue with IE9.. anyone here found a solution that does NOT involve ejecting? .. using the polifills does not seems to do any magic.

@seanbecker15
Copy link

Hey, I'm having the same issue with IE9.. anyone here found a solution that does NOT involve ejecting? .. using the polifills does not seems to do any magic.

I have a fully functional application that runs in IE9. There were several fixes I had to make that are not mentioned in this thread. I ejected but if you provide your error I may be able to point you in the right direction.

@InSuperposition
Copy link

InSuperposition commented Oct 18, 2020

After reading this comment, I found the following solution works with hot reload. I'm on v3.4.1 of react-scripts

  1. In my local node_modules folder, I modified one file in react-dev-utils (a create-react-app dependency) by removing the offending function call and the chalk import statement

  2. Then I used patch-package to patch my project's react-dev-utils

  3. added the package for CRA's polyfills

import "react-app-polyfill/ie9"
import "react-app-polyfill/stable"
  1. I added a meta tag to <head /> element to public/index.html.
    (optional) It prevents IE users from enabling its "compatibility" mode
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

Its also possible browserlist's development environment may need additional configuration.

@yjwSurCode
Copy link

@vincent Uncaught SyntaxError: Use of const in strict mode /sattic/js/main.chunk.js 199:1 SyntaxError :Use of const in strict mode

@yjwSurCode
Copy link

I found the dependencies cause the bug

create-react-app -> react-scripts/config/webpack.config.js -> react-dev-utils/webpackHotDevClient.js -> react-dev-utils/formatWebpackMessages.js -> chalk -> ansi-styles -> Map

and I think we need setupPolyfill ( just like setupProxy),it should be insert before webpackHotDevClient:

entry: [
  paths.setupPolyfill,
  isEnvDevelopment &&
  require.resolve('react-dev-utils/webpackHotDevClient'),
  // Finally, this is your app's code:
  paths.appIndexJs,
]

I created a create react app to run on Android 5.0. This problem does not appear in the higher version of Android. Some people say it is node_ modules/webpack-dev-server/client/ index.js There is no compilation here. I need to compile manually. I don't know how to configure it

@yjwSurCode
Copy link

isEnvDevelopment

I finally have a workaround after looking at this for a couple of days

I had to change the client for WebpackDevServer from react-dev-utils/webpackHotDevClient to the alternative of webpack/hot/dev-server

You have to go to your webpack.config.js file and swap out this line:

isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient'),

with this one:

isEnvDevelopment && require.resolve('webpack/hot/dev-server'),

I created a create react app to run on Android 5.0. This problem does not appear in the higher version of Android. Some people say it is node_ modules/webpack-dev-server/client/ index.js There is no compilation here. I need to compile manually. I don't know how to configure it

but!!! i use your method It didn't work

@MiroslavJag
Copy link

MiroslavJag commented Mar 10, 2021

After reading all the comments this what works for my app:

  1. Install react-app-polyfil
    npm i react-app-polyfil
  2. Import react-app-polyfill in index file
    import "react-app-polyfill/ie11"
    import "react-app-polyfill/stable"
  3. Add ie11 to browserslist in package.json
    "development": [ "ie 11", ]
  4. Delete node modules
    rm -rf node_modules
  5. Clean the npm cache
    npm cache clean --force
  6. Install node modules
    npm install
  7. Start the project

@raix
Copy link
Contributor

raix commented Dec 17, 2021

Can this issue be closed - it seems to be resolved?
(As for CRA v5 we depend on the Webpack 5 client)

@raix raix modified the milestones: 5.1, 5.x Dec 17, 2021
@cliedeman
Copy link
Author

@raix the core of the issue was never about webpack but imported deps that break when developing in older browsers. I no longer need this so I will close it. If someone else reports an error they can open a new issue

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

No branches or pull requests