observable({k: 1}) throwing error in replit node environment.
Note: Works fine in browser and in local nodejs environment. I will raise this but report with repl.it (https://repl.it/bugs/p/mobx-fails-in-nodejs-environment) Please close if you think it is irrelevant.
I have a:
- [x] Issue:
- [x] Provide error messages including stacktrace
Error: [mobx] The provided value could not be converted into an observable. If you want just create an observable reference to the object use 'observable.box(value)'
at invariant (/home/runner/node_modules/mobx/lib/mobx.js:94:15)
at fail (/home/runner/node_modules/mobx/lib/mobx.js:89:5)
at createObservable (/home/runner/node_modules/mobx/lib/mobx.js:507:5)
at evalmachine.<anonymous>:16:23
at Script.runInContext (vm.js:133:20)
at Object.runInContext (vm.js:311:6)
at evaluate (/run_dir/repl.js:133:14)
at ReadStream.<anonymous> (/run_dir/repl.js:116:5)
at ReadStream.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
- [ x] Provide a minimal sample reproduction. Create a reproduction based on this sandbox
- [x] Did you check this issue wasn't filed before?
- [x] Elaborate on your issue. What behavior did you expect? No error
- [x] State the versions of MobX and relevant libraries. Which browser / node / ... version? node v10.16.0, mobx v5.11.0
- [x] What problem would it solve for you? Playing around with libraries on repl
- [x] Do you think others will benefit from this change as well and it should in core package (see also mobx-utils)?
Well, I took a brief look at it and it's indeed strange behavior. Considering that isPlainObject returns true (and it's the same check we have in the source), it should work just fine.
Without debugging it's pretty much impossible to figure out what's wrong there. Maybe they are running that code through some tooling/optimizers which may cause weird behavior.
I will leave this open if someone can come up with ideas.
Btw, I've created same reproduction in CodeSandbox which also has a Node environment and it works there just fine, although I couldn't find the Node version
https://codesandbox.io/s/heuristic-archimedes-pqd7j
So you might consider using that instead of Repl which does who knows what there :)
Looks like mobx module loaded in separated global environment:
mobx.observable.__proto__.__proto__
=> {}
mobx.observable.__proto__.__proto__.constructor
=> [Function: Object]
mobx.observable.__proto__.__proto__.constructor === Object
=> false
Sounds like a ReplIT bug, not a MobX bug :)
Closing until someone has a convincing argument this is a MobX, and not a ReplIT bug
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.