facebook / create-react-app

Set up a modern web app by running one command.

Home Page:https://create-react-app.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chrome debugger breakpoints fail with react-scripts 2.x after hot-update

nerdcity opened this issue Β· comments

Is this a bug report?

yes

Did you try recovering your dependencies?

test-cra $npm --version
5.6.0

test-cra $yarn --version
1.12.3

Which terms did you search for in User Guide?

I looked for "hot-update" and "breakpoint"

Environment

System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Binaries:
Node: 8.11.1 - ~/.nvm/versions/node/v8.11.1/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 5.6.0 - ~/.nvm/versions/node/v8.11.1/bin/npm
Browsers:
Chrome: 71.0.3578.98
Firefox: 63.0.1
Safari: 11.1.2
npmPackages:
react: ^16.7.0 => 16.7.0
react-dom: ^16.7.0 => 16.7.0
react-scripts: 2.1.1 => 2.1.1
npmGlobalPackages:
create-react-app: Not Found

Steps to Reproduce

  1. ran "yarn create react-app test-cra"
  2. ran "yarn install"
  3. ran "yarn start"
  4. Chrome opened a window for http://localhost:3000, with the app in it
  5. I opened Chrome dev tools and went to the source tab
  6. I hit cmd-P and opened App.js
  7. I set a breakpoint at line 7, the first line of the render() method
  8. I clicked on the "reload this page" arrow in the "React App" browser window
  9. the debugger in dev tools window stopped at the breakpoint
  10. I hit F8 to unpause

** this is all good, and I am able to repeat steps 8-10 successfully any number of times

  1. in IntelliJ I edited the App.js file so it was like this:
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt={this.foo} />
          <p>
            Edit <code>src/App.js</code> and save to reload.
          </p>
          <a
            className="App-link"
            href="https://reactjs.org"
            target="_blank"
            rel="noopener noreferrer"
          >
            Learn React
          </a>
        </header>
      </div>
    );
  }

  foo = 'bar';
}

export default App;

NOTE: I did not move the position of the breakpointed line within the file.

  1. I saw that the app recompiled and reloaded successfully. The code as pasted above is what appeared in the devtools source tab, and the breakpoint was positioned at the same place. However, the debugger did not stop at the breakpoint.
  2. I clicked on the "reload this page" arrow in the "React App" browser window, but the debugger does not stop there anymore. I see that at the bottom of the Source tab, it now says "(source mapped from main.{guid}.hot-update.js)".
  3. I stopped execution of the yarn start task with control-C.
  4. I re-ran "yarn start".
  5. the debugger does not stop on the initial page load, but it does stop on every subsequent page load (when I click the "reload this page" arrow).
  6. I see that on the bottom of the devtools Source tab, it now says "(source mapped from main.chunk.js)".

My apologies if the format of how I described this is not matching the following bullet points - I think I have done what they ask, but in a more interleaved fashion. I think the essence is that I have described a reproducible demo with what I expected, what I did, and what happened as a result.

NOTES: this does NOT happen to me when I am using react-scripts 1.1.4 (in the full-blown app where I encountered the issue) but only appeared when I upgraded to 2.x (first 2.0.5 and now 2.1.1).

Thanks very much for your help with this!

commented

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

commented

I'm having the same issue. Working with react-scripts 2.0.5

facing same issue here.

I'm hitting this issue as well. Only happens in Chrome, not Firefox. Chrome has a long history of issues with sourcemaps, and I found that changing webpack's source map type from cheap-module-source-map to eval-source-map fixes the issue. Fortunately, that change has already been made at #5060, it just hasn't made it into a release yet.

@jasonLaster @Timer (sorry if you're the wrong people to ping), any chance we can get a patch release with that fix? (This feels like a pretty major issue.)

@russelldavis a release should be out shortly :)

This is now released. πŸ˜„

Reverted due to a bug in webpack.

Is there a timeline for this release or are you waiting for webpack to fix their issues? I have the same problem, if you close dev tools then reopen them it works again, but only once.

πŸ‘ same problem

/cc @russelldavis Somebody can create reproducible test repo for #6433 in webpack repo, looks like a bug what we need fix

This issue is killing me

Debugging in Chrome is unusable right now. This is major showstopper.

@Timer @ianschmitz can you help the community understand the prioritization of this issue? Breakpoints being unusable in CRA apps seems like it should be a top priority, but empirically it doesn't seem to be.

Does Facebook not use CRA internally? Does Facebook not use breakpoints internally? Are breakpoints just not considered a critical feature? Something else entirely?

Thanks!

Switching source-maps from cheap-module-source-map to eval-source-map breaks the error overlay functionality. We can't really have one fix breaking other things, so that change was reverted for now. You can pin react-scripts to 2.1.4 if you need to have Chrome debugging functionality. I have an issue open at Webpack to look at this webpack/webpack#8910, feel free to subscribe to it for any updates.

This project is maintained by a team of volunteers that don't work at Facebook (AFAIK). I can tell you that Facebook also doesn't use CRA internally.

commented

@bugzpodder

Switching source-maps from cheap-module-source-map to eval-source-map breaks the error overlay functionality. We can't really have one fix breaking other things, so that change was reverted for now. You can pin react-scripts to 2.1.4 if you need to have Chrome debugging functionality. I have an issue open at Webpack to look at this webpack/webpack#8910, feel free to subscribe to it for any updates.

This project is maintained by a team of volunteers that don't work at Facebook (AFAIK). I can tell you that Facebook also doesn't use CRA internally.

How to

Switching source-maps from cheap-module-source-map to eval-source-map

??

Where does webpack config live in the app?

Goto node_modules/react-scripts/config/webpack.config.js, look up cheap-module-source-map and change to eval-source-map. This is temporary and you'll have to do this every time you change your package configuration.

I've used this tool to override cheap-module-source-map with eval-source-map

https://github.com/arackaf/customize-cra

looking forward to a permanent fix though, since this is indeed a heavy handed work around. Also, when using eval-source-map and doing CMD + P in the debugger to find files, it will search through the minified files as well as the source mapped ones, which is definitely not ideal :\

commented

Using this to the package.json worked for me: "start:debug": "react-scripts --inspect start --no-cache --runInBand",

Does anyone have the same issue after upgrading to CRA 3.x? This still seems to be an issue in CRA 3.x?

@jsdevtom worked! but why??

Doesn't work with 3.0 for me as well, very annoying and I have no clue how to fix it

@hmeerlo read @jsdevtom 's solution. it works

@adamchenwei Ah sorry, I focused on @bugzpodder solution but that was a workaround that stops working every now and then. This one does work indeed, thanks.

Thank you @jsdevtom . It has been so stressful to develop like this until now in Chrome

commented

@adamchenwei I don't know, I haven't delved in to the react scripts enough to find out.
@miggu You're very welcome

Please be aware that I consider this a temporary solution. The breakpoints still fail for me after an error is thrown in the app. On average I would say I can debug develop for about 30 minutes before I need to run the command again and thus hit the breakpoints.

I did the v2 revert solution as described by @bugzpodder. Works so far. Hopefully issue will be fixed soon tho.

commented

@jsdevtom

Using this to the package.json worked for me: "start:debug":

How do you start the app then?

$ npm start ?
$ npm run start:debug ?

I ended up working around this by using react-app-rewired. I am running react-scripts 3.0.1.

Steps:

  1. npm install react-app-rewired --save-dev or yarn add react-app-rewired --dev
  2. Create a new file in your root project level called config-overrides.js
  3. Paste the following code in config-overrides.js:
module.exports = function override(config, env) {
  if (env !== 'production') {
    config = { ...config, ...{ devtool: 'cheap-module-eval-source-map' } };
  }
  return config;
}
  1. In your packages.json replace your run scripts with the following:
"scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-app-rewired eject"
  },

I'm just wondering why everyone is trying to replace the devtool with eval-source-map, there are many devtools available and cheap-module-eval-source-map seems to work fine for me, unless I'm missing something.

@j3ko The error overlay displays wrong lines if cheap-module-eval-source-map is used.

commented

@jsdevtom

Using this to the package.json worked for me: "start:debug":

How do you start the app then?

$ npm start ?
$ npm run start:debug ?

You use npm run start:debug. Here is the respective documentation: https://docs.npmjs.com/cli/run-script.html

I've still encountered this issue even when using solution presented by @jsdevtom . The only sure fire way I can set breakpoints is by using debugger; in code. It's not as pleasant as just setting the point in devtools, but it makes things predictable at least.

commented

I still have this problem, is there any solution for this issue?

Try this package
https://www.npmjs.com/package/react-breakpoint-fix

just install the package and run react-breakpoint-fix from the terminal.

This fixed it for me. I'm using react-scripts@3.x

Try this package
https://www.npmjs.com/package/react-breakpoint-fix

just install the package and run react-breakpoint-fix from the terminal.

This fixed it for me. I'm using react-scripts@3.x

If you can use cheap-eval sure. I'm not sure adding a dependency to regex the eval tool to the cheap one is so wise. I definitely know this would not fly within my team.

I think it can be fixed if we will be able to choose sourcemap type via environment variable.
#7495

So to clarify, is this still an issue? As someone looking to use the react-error-overlay plugin in a non-CRA app[1] (which already has full control of the sourcemap devtool) , this comment from @russelldavis seems concerning: #6433 (comment)

It seems like there's no current way to have fully working sourcemaps as well as react-error-overlay working in an app?

All of the comments in this thread mainly discuss switching the sourcemap type in webpack, but don't seem to take into account that this will seemingly reintroduce #6433. Curious what the current state is and whether there's an open webpack issue somewhere if it's indeed a webpack bug.


[1] (or perhaps investigate using it as part of a React fast-refresh implementation: facebook/react#16604 (comment))

I can confirm that this is still an issue occasionally. I just ran into it again, even using the start:debug solution of @jsdevtom . I have no clue what to do to work around it, except using debugger statements.

Also confirming that this is still an issue even with @jsdevtom's fix. I'm having to restart my app to get debugging work again after a hot reload.

Just to confirm, unless every line of my program is actually in a file named fs.js and of which all are the seventh line (which is definitely not the case πŸ˜‰), this is indeed still broken.

@RobertWHurst - fix is merged so it should be in the next react-scripts release. Keep your eye on npm outdated.

@justingrant That's great to hear. will do πŸ‘

Still facing this issue as well.

@RobertWHurst - turns out that the fix in #7022 isn't the same issue as this one. This problem is still happening. FWIW, what I've seen in the past is that there are three separate (maybe related) problems in this area:

  1. Breakpoints are not adjusted when you add new lines of code above an existing breakpoint and then do a hot update. For example, if you have a breakpoint on line 100 and you insert 2 lines between lines 98 and 99, then the breakpoint may not move to 102 as expected. It might stick on line 100, even through the "new" line 100 is not the same code as the "old" line 100.
  2. If you save a file in VSCode while the VSCode debugger is paused at a breakpoint, then some breakpoints won't work properly in the hot-updated file after you continue, where "won't work properly" means that you can't set breakpoints on valid code lines, you can set breakpoints on whitespace lines in the new file, etc. For this reason, I don't save changes while the debugger is stopped at a breakpoint.
  3. If you run your app in the VSCode debugger while also having the same app open in Chrome Dev Tools, then you'll sometimes get "zombie" breakpoints where code execution will stop on a line that doesn't have a breakpoint on it in VSCode. It's possible that this is the same problem as (2) above-- it might only happen when you save changes in VSCode while the app is stopped in the VSCode debugger and while the Chrome dev tools are open in the browser.

In all cases, restarting the debug session (stop debugging, stop the npm start process, restart the npm start process, and start debugging again) will fix the problem.

I haven't done the validation to figure out reliable repro cases for all these, so it's possible that all three of these are the same root cause.

Hope this info is helpful. It looks like this issue and #8165 both reflect some (maybe all) of the problems that I described above.

Given that there's a completely new hot-reload solution called Fast Refresh coming to React (it's already been released for React Native), it's possible that no fixes will be made for the current hot-reload solution.

Does anyone know if there's an existing CRA issue that's tracking adoption of the new Fast Refresh solution in CRA? I wasn't able to find one.

@bugzpodder Would you know what's so special about 2.1.4 that make it work with chrome while others not? Can't we just apply that change to the CRA? (I scanned through some of the links, still did not seems to find a real solution)

also why This project is maintained by a team of volunteers that don't work at Facebook (AFAIK). I can tell you that Facebook also doesn't use CRA internally. if its still under org of Facebook, but it does not maintain it....?

commented

Hi, has anyone had any luck with this?

Breakpoints still are not working in react-scripts 3.3.1.
I tried @jsdevtom 's solution but it did't make any difference, also tried a variety of source map configs in webpack's devtool property.

It's getting really frustrating

UPDATE: I also tried downgrading react-scripts to 2.1.4 and breakpoints are still not working as expected...

@bugzpodder Would you know what's so special about 2.1.4 that make it work with chrome while others not? Can't we just apply that change to the CRA? (I scanned through some of the links, still did not seems to find a real solution)

2.1.4 was working possibly because of #5060, you can use react-app-rewired to patch webpack config if you wishes to do so.

also why This project is maintained by a team of volunteers that don't work at Facebook (AFAIK). I can tell you that Facebook also doesn't use CRA internally. if its still under org of Facebook, but it does not maintain it....?

Yes, but they are under no obligation to give it up. You'll have to take it up with someone who works there currently.

Still having this same issue with react script 3.3.0, the breakpoints works just sometimes with no apparent pattern

Same issue for me with:

  • react script 3.4.1 (freshly new created app)
  • chrome 81.0.4044.92
  • os x 10.14.6

seems to work randomly.

Adding the no-cache flag to the start script npm command doesn't help, as suggested here:
CRA chrome issue solution

Same issue here. Running:

  • react-scripts: 3.2.0
  • Microsoft Edge (Chromium) 81.0.416.53
  • Windows 10 Pro Build 18363

With Firefox 75 it works fine, though.

Not sure if it's related, but I am facing the issue without using react-scripts. I am only using react-hot-loader (4.12.18)

I'm having the same issue using yarn. When I restart the server, then the debug works once until I hot reload the code.

To fix the problem with sourcemaps in Chrome, you need to enable the 'Enable JavaScript source maps' settings

image
image
image
image

@real4 that's not the problem we're reporting.

  1. I have Javascript source maps enabled

Captura de pantalla 2020-05-03 a las 13 03 04

  1. I have the no-cache option set in start npm task
  "scripts": {
    "start": "react-scripts start --no-cache",
    "build": "react-scripts build",
    "test": "react-scripts test --no-cache",
    "eject": "react-scripts eject"
  },

Neither of those seem to solve the problem reported, it seems to come with hot reloading as @mustafahafidi said. When you just start the server the breakpoint works properly, but once you update your code and it's hot reloaded it doesn't work anymore.

Are there plans to solve this after a year? Thinking about starting the project ejecting or using another tool.

Switched to Firefox for this, supposedly it should keep logpoints there, lets see

Issue still exists as originally reported by @nerdcity

vscode 1.46.1
yarn 1.22.4
react-scripts 3.4.1
react 16.13.1

Both with Firefox 77.0.1 and Chromium 83.0.4103.97

commented

I'm still having this issue with chrome.
But works with "node scripts/start.js --no-cache" --no-cache flag.
This issue is also related with locked #5846

Perhaps I did something wrong, but --no-cache doesn't seem to be helping in Chrome. Appears ok in Firefox, but I didn't try that without the flag.

still have the problem, drive me crazy now i am putting debugger all over the code

Also facing the same problem. I have to stop the development server and start it again. Thats a huge pain and time consumption. Is there any hack fix for this?

@bugzpodder solution is a life saver :)

commented

I have the same problem in version 86.0.4240.111 (Official Build) (64 bits) in Ubuntu 20.04, the breakpoints stop working when the page is reloaded. I disabled hardware acceleration, I changed my scripts in my package.json with "--no-cache" but I couldn't fix it.

I Need help!

@EliasBobadilla (and anyone else) - CRA just released v4, which includes Fast Refresh replacing Hot Reload. I'm not seeing the issue anymore now that I've upgraded.

https://github.com/facebook/create-react-app/releases/tag/v4.0.0

I'm curious if this has fixed the issue for others as well.

commented

@meatnordrink today at morning I got the last stable version of chrome 86.0.4240.183 , launched yesterday.
https://chromereleases.googleblog.com/2020/11/stable-channel-update-for-desktop.html
and the problem with breakpoints is gone.

Anyway I'm developing a new app some weeks ago. I think is a good oportunity to change to create-react-app 4.0.0 version now

One solution I found to solve this warning was to downgrade the react-script package to version 3.4.4 and this solved the warnings

I still have the same issue, I'm unable to set breakpoints

image

With, or without the "sourceMapPathOverrides" I've seen mentioned in a few places (E.G https://stackoverflow.com/questions/61953992/breakpoints-not-working-debugging-react-app-in-chrome-through-visual-studio-code/62207696#62207696)

image

It seems I CAN trigger a debugger within the editor, via using the "debugger" statement, rather than clicking on an actual breakpoint. The file the break appears in, however isn't my source

image

Debugger statement triggers in > /home/wsl-tom/git/project
Actual file where debugger was written > //wsl$/Ubuntu-18.0/home/wsl-tom/git/project

I tried using the sourceMapPathOverrides rule of > "/home/wsl-tom/*": "//wsl$/Ubuntu-18.0/home/wsl-tom/*",, however it still triggers in wrong file. And I also still have "unbound breakpoint"

I'm curious if this has fixed the issue for others as well.

After upgrading to CRA v4. I can confirm this bug is no longer exist

I have version 4.0.3 and the problem still persists on edge (chromium version) 88.0.705.74
package.json:

{
  "name": "testgrpc.client.web",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.11.3",
    "@testing-library/jest-dom": "^5.11.9",
    "bootstrap": "^4.6.0",
    "final-form": "^4.20.1",
    "final-form-arrays": "^3.0.2",
    "google-protobuf": "^3.14.0",
    "grpc-web": "^1.2.1",
    "jquery": "^3.5.1",
    "merge": "1.2.1",
    "mui-rff": "^3.0.3",
    "popper.js": "^1.16.1",
    "react": "16.14.0",
    "react-dom": "16.14.0",
    "react-final-form": "^6.5.2",
    "react-final-form-arrays": "^3.1.3",
    "react-redux": "7.2.2",
    "react-router": "5.2.0",
    "react-router-dom": "5.2.0",
    "react-scripts": "^4.0.3",
    "reactstrap": "8.9.0",
    "redux": "4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-saga": "^1.1.3",
    "svgo": "1.3.0",
    "yup": "^0.32.9"
  },
  "devDependencies": {
    "@testing-library/react": "^11.2.5",
    "@types/jest": "26.0.20",
    "@types/node": "12.11.6",
    "@types/react": "16.14.3",
    "@types/react-dom": "16.9.10",
    "@types/react-redux": "7.1.16",
    "@types/react-router": "5.1.11",
    "@types/react-router-dom": "5.1.7",
    "@types/reactstrap": "8.0.6",
    "@types/redux-devtools-extension": "^2.13.2",
    "@types/redux-saga": "^0.10.5",
    "@types/yup": "^0.29.11",
    "@typescript-eslint/parser": "^4.15.2",
    "cross-env": "6.0.3",
    "eslint-plugin-flowtype": "^3.13.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jsx-a11y": "6.2.3",
    "eslint-plugin-react": "^7.22.0",
    "eslint-plugin-react-hooks": "4.2.0",
    "jest-environment-jsdom-sixteen": "^1.0.3",
    "nan": "^2.14.1",
    "typescript": "4.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "cross-env CI=true react-scripts test --env=jest-environment-jsdom-sixteen",
    "eject": "react-scripts eject",
    "lint": "eslint ./src/**/*.ts ./src/**/*.tsx"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

yarn version: 1.22.4

The year is 2023! And this is a problem on a clean create-react-app
If you launch the Chrome bugger with a breakpoint enabled it will hang loading the site. Now the running react-script start is corrupted.

If you then
a) remove all breakpoints
b) react script start
c) Launch Chrome debugger again
it will display, and then you can start adding breakpoints.

Tested on two mutually exclusive computers.

react-scripts : 5.0.1
Literally no changes to create-react-app except to add a <button/> to test clicking.

I'm seeing this same problem, although my setup is more complex and I haven't been able to isolate it down yet. Everything was working fine and then ? something changed ? and now breakpoints cause the browser to hang on refresh:

  1. start debugging, works fine
  2. set a breakpoint, works fine
  3. keep playing with the app works fine.
  4. press the reload button in chrome, and it hangs.

I know this isn't a particularly useful bug report; I mostly want to give a +1 to @john-twigg-ck

Just popping in to say that as quickly and mysteriously as this bug appeared, it has now disappeared again. I don't recall making any updates to my dev environment along the way... maybe it was a chrome bug that got auto-updated away.

Just popping in to say that as quickly and mysteriously as this bug appeared, it has now disappeared again. I don't recall making any updates to my dev environment along the way... maybe it was a chrome bug that got auto-updated away.

Me too. Someone probably silently updated Chrome.