question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot assign to read only property 'product' of object '#<WorkerNavigator>' initializeCore.js line 176

See original GitHub issue

Description

I’ve updated my app from react-native 0.34 to 0.37. Then when launching the app I encounter: Cannot assign to read only property 'product' of object '#<WorkerNavigator>' initializeCore.js line 176

Now I realize that nearly no-one is going to be able to reproduce this as it is most probably a clash with one of the modules I use. Here is my package.json:

"dependencies": {
    "lodash": "^4.16.6",
    "moment": "^2.15.1",
    "ramda": "^0.22.1",
    "react": "^15.3.2",
    "react-native": "^0.37.0",
    "react-native-accordion": "^1.0.1",
    "react-native-button": "^1.7.0",
    "react-native-invertible-scroll-view": "^1.0.0",
    "react-native-maps": "^0.11.0",
    "react-native-modal-picker": "0.0.16",
    "react-native-pullable-view": "^1.0.2",
    "react-native-router-flux": "^3.37.0",
    "react-native-theme-picker": "^1.0.0",
    "react-native-vector-icons": "^3.0.0",
    "react-redux": "^4.4.5",
    "redux": "^3.6.0",
    "redux-persist": "^4.0.0-alpha5",
    "redux-thunk": "^2.1.0",
    "tcomb-form-native": "^0.6.1",
    "uuid": "^2.0.3"
  },
  "devDependencies": {
    "babel-preset-react-native": "^1.9.0",
    "babel-register": "^6.14.0",
    "remote-redux-devtools": "^0.5.3",
    "remote-redux-devtools-on-debugger": "^0.6.3",
    "tap-spec": "^4.1.1",
    "tape": "^4.6.0"
  }

But I think that we have a bug in the code and here is why. I did launch a new project with react-native init awesomeApp

The awesomeApp launched without error, unlike the app that I updated. However if you do console.log(global.navigator)in the render function of that dummy app I see that the product property hasn’t changed to ReactNative. For me it stays “gecko”.

I downgraded my app to 0.36.0 and it’s not crashing. The new code in intializeCore has been pushed with this commit: https://github.com/facebook/react-native/commit/606fc1148709357c3da9fb5bc45abaa251205378

if I change navigator.product = 'ReactNative'; to Object.defineProperty(navigator, 'product', {value: 'ReactNative'}); (as it was before)

then my app doesn’t crash on 0.37 and the output of console.log(global.navigator) is product = ‘ReactNative’ both in my app and in the dummy app.

Reproduction

  1. Clone this repository: https://github.com/compojoom/bugreactnative launch the app as usual - npm install and then launch it with xdebug.

Enable remote debugging and look at the console output - it should say “Gecko” instead of “ReactNative”

If you change the code in node_modules/react-native/Libraries/Core/InitializeCore.js on line 176 to: Object.defineProperty(navigator, 'product', {value: 'ReactNative'});

then the output in the console should read “ReactNative”

Additional Information

  • React Native version: 0.37

  • Platform: iOS (possible on android as well)

  • Operating System: MacOS

  • works as expected with react native version: 0.36

If you also consider this a bug I would be happy to make a pull request.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
idecommented, Nov 17, 2016

We don’t want to return Gecko probably. Something like this seems like what we want:

 Object.defineProperty(GLOBAL.navigator, 'product', {
  enumerable: true,
  configurable: true,
  get() { return 'ReactNative'; },
  set(value) {}
})
0reactions
compojoomcommented, Nov 17, 2016

Ok, I thought about the same. I’ll do a PR tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Cannot assign to read only property [closed]
I'm wondering if there anything I can do in typescript to mediate the error above? Please let me know if I can provide...
Read more >
Cannot assign to read only property of Object in JavaScript
The error "Cannot assign to read only property of object" occurs when we try to change a property of an object that has...
Read more >
[Cannot assign to read only property '<field_name>' of object ...
This type of error(Cannot assign to read-only property) generally occurs on update of public property @api decorator variable value.
Read more >
typescript cannot assign read only propertie - You.com
Upgrading to typescript 4.1 which apparently introduced React 17 JSX Factories causes the error Cannot assign to read only property 'jsx' of object...
Read more >
TypeError: Cannot assign to read-only property "parent"
3 version simply because JavaScript (which is what QML is based on) allows assigning any values to non-existing properties of any object (which ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found