18

When I inspect my code using the react devtools, I'm noticing some hooks trigger this error and cause the "parse hook names" action to error out. When I inspect the react dev tools, it outputs:

main.js:4878 Error: Could not find runtime location for line:177321 and column:81
    at Object.originalPositionFor

Following from this thread on Facebook/React issues, it seems like it might be webpack sourcemap related. Does someone have any ideas as to what could be causing this? It's happening not just with custom hooks, but standard useState and useCallback hooks in my codebase.

React Dev Tools react dev tools error

sgarcia.dev
  • 5,123
  • 12
  • 37
  • 68
  • 2
    What webpack `devtool` are you using? Switching to `cheap-module-source-map` fixed a similar issue for me – Ty Hitzeman Feb 13 '22 at 18:23
  • Tks @TyHitzeman! It's works for me! – LuanLuanLuan Mar 09 '22 at 14:37
  • @TyHitzeman How do you switch it? I am using create react app and cant find the webpack config – polvoazul Mar 22 '22 at 19:13
  • 1
    @polvoazul Updating CRA's webpack config is discussed here: https://stackoverflow.com/questions/63280109/how-to-update-webpack-config-for-a-react-project-created-using-create-react-app Once you can update your webpack config, see the `devtool` section of the docs: https://webpack.js.org/configuration/devtool/ – Ty Hitzeman Mar 25 '22 at 18:03
  • 1
    @TyHitzeman That actually fixed this issue for me as well, it would be great if you could post it as an answer for everyone's benefit :) – Sumit May 24 '22 at 10:04

2 Answers2

0

This is indeed related to how your webpack devtool selection handle source maps.

If you want a quick fix, try updating your webpack like so:

// webpack.config.js

module.exports = {
  //  ...

  return {
     devtool: "cheap-module-source-map",
     
     // or if you're using the same webpack config for prod + dev:
     // devtool: process.env["NODE_ENV"] === "development" ? "cheapmodule-source-map" : "source-map",

    // ... 
  }
}

The cheap-module-source-map has worked for me and some others here. But it isn't necessarily the only one, and it comes with some tradeoffs. If you want to experiment with other devtools and understand more, see the webpack devtool docs

Ty Hitzeman
  • 785
  • 1
  • 11
  • 23
-2

While I don't see the error line that you posted, this often happens to me, and it's usually fixed by updating my browser (Brave).

DharmanBot
  • 1,080
  • 2
  • 4
  • 10