mobxjs / mobx-react

React bindings for MobX
https://mobx.js.org/react-integration.html
MIT License
4.85k stars 349 forks source link

Attempted import error: 'observerBatchingOptOut' is not exported from 'mobx-react-lite'. #894

Closed michaelaflores closed 4 years ago

michaelaflores commented 4 years ago

Intended outcome

Using mobx-react 6.3.0, and running a build of an app consuming it, should work.

Actual outcome

Failed to compile
./node_modules/mobx-react/dist/mobxreact.esm.js
Attempted import error: 'observerBatchingOptOut' is not exported from 'mobx-react-lite'.
This error occurred during the build time and cannot be dismissed.

I believe what's happening is that if you run this install fresh, you'll get MobX-react-lite @ 2.2.1, which doesn't have this export. They have a related issue for something else they removed but not for this particular export. At any rate, I think mobx-react should have this sub-dependency locked to a known working version in its package json so that consumers don't pick up accidental breaking changes.

How to reproduce the issue

  1. Create a new react app
  2. npm install mobx-react@6.3.0
  3. Observe that a sub dependency is installed, mobx-react-lite 2.2.1
  4. Observe build error

Versions

"mobx": {
  "version": "5.15.4",
},
"mobx-react": {
  "version": "6.3.0",
  "requires": {
    "mobx-react-lite": ">=2.2.0"
  }
},
"mobx-react-lite": {
  "version": "2.2.1",
},
danielkcz commented 4 years ago

The observerBatchingOptOut is deprecated and won't be used anymore. PR welcome to remove its export from this lib.

michaelaflores commented 4 years ago

@FredyC I wouldn't mind picking this up -- I don't actually see where it's used in this current version of mobx-react though, I seem to turn up no results for observerBatchingOptOut. Any chance you could point me to a good place to look? Seems like you all are actually using batchingOptOuthere so I'm surprised this error occurs.

danielkcz commented 4 years ago

I am surprised as well. The 6.3.0 should indeed work correctly. Are you sure you are not running into some NPM/Yarn caching issues?

https://unpkg.com/browse/mobx-react@6.3.0/dist/mobxreact.esm.js

No mention of observerBatchingOptOut here.

michaelaflores commented 4 years ago

@FredyC good point. I'm going to double check and report back.

JamesRamm commented 4 years ago

@FredyC we are encountering this issue on our CI server with no yarn caching enabled. We had no issues until ~3days ago and have not (knowingly) updated any dependencies....

danielkcz commented 4 years ago

@JamesRamm And do you have 6.3.0? Do you commit yarn.lock? The change happened in the underlying mobx-react-lite, but with a lock file it should keep the old version.

JamesRamm commented 4 years ago

@FredyC yarn.lock is not committed - but our mobx-react version is pinned to 6.2.2 You are suggesting that updating to 6.3.0 should fix this?

danielkcz commented 4 years ago

Yea well, without a lock file it means that the underlying mobx-react-lite will be always updated to the last version and that's what caused your issue. Generally, I would recommend you to commit yarn.lock if you want a stable CI environment. Even with pinning versions you never know if transient dependencies are pinned too (usually they are not). Upgrading to 6.3.0 should fix this problem.

michaelaflores commented 4 years ago

@FredyC verified this problem existed between the mouse and keyboard, 6.3.0 does indeed work as expected. Thanks for your help. 👍