react icon indicating copy to clipboard operation
react copied to clipboard

[DevTools Bug]: React instrumentation encountered an error: TypeError: e.hasOwnProperty is not a function.

Open molnard1 opened this issue 2 years ago • 2 comments

Website or app

https://github.com/molnard1/react-template/tree/devtools-bug

Repro steps

  1. Clone the above repo (the devtools-bug branch should be used), install dependencies (npm i)
  2. Build/start it in development mode (npm run watch)
  3. Observe the following error in console, along with devtools not working: image image

As far as I can tell, this appears to be caused by Axios, as this error does not happen before adding it to the project.

How often does this bug happen?

Every time

DevTools package (automated)

No response

DevTools version (automated)

No response

Error message (automated)

No response

Error call stack (automated)

No response

Error component stack (automated)

No response

GitHub query string (automated)

No response

molnard1 avatar Dec 20 '23 09:12 molnard1

e should be object not variable, Error is due to the: const e = "some string"; // this is a variable not obejct var hasProperty = e.hasOwnProperty("someProperty"); This is how your code should look like: const e = { name: "xyz" }; const prop = e.hasOwnProperty("name"); console.log(prop); // output will be true because name is property of e

Kartikkittad avatar Dec 22 '23 06:12 Kartikkittad

I've had a bit of time to look over this again, and it seems that the issue is actually caused by esbuild, specifically, the development build command: esbuild src/js/index.js --bundle --loader:.js=jsx --format=cjs --outfile=public/dist/bundle.js --watch changing --format=cjs (or --format=esm, which also triggers the same error) to --format=iife fixes the issue. The reason this doesn't happen in the production build is because --minify seems to remove the code that's causing the DevTools error in cjs/esm mode.

molnard1 avatar Jan 06 '24 19:01 molnard1

Thanks @molnard1 ,

This error occurs when using React + ESBuild. This works for me:

Development mode: --format=iife and minify=false

Production: --format=cjs and minify=true

taronsarkisyan avatar Feb 03 '24 13:02 taronsarkisyan

Closing this, since the solution is found and related to the build infra.

hoxyq avatar Jun 27 '24 13:06 hoxyq