Attempted import error: 'makeObservable' is not exported from 'mobx'

3.3k Views Asked by At
import React from 'react'
import { observer } from 'mobx-react'; //Cause of Error

export default observer(App); //At the bottom of the code

the only line causing an error is import { observer } from 'mobx-react'; and gives my the following error

./node_modules/mobx-react-lite/es/utils/assertEnvironment.js
Attempted import error: 'makeObservable' is not exported from 'mobx'.
2

There are 2 best solutions below

1
On

update mobx to last version and try again

0
On

While building my project, I encountered an error in my console similar to the following:

Failed to compile.
./somefile/some.file.js
Attempted import error: 'makeObservable' is not exported from 'mobx'.

This issue arises because versions 5 and below of the mobx library do not include an exported makeObservable member in their interface. You can verify this by checking your yarn.lock or package-lock.json file for the installed version. To resolve this issue, update the mobx library to the latest version. I am currently using the following versions:

"mobx": "6.8.0",
"mobx-react": "7.6.0",

Updating to these versions should resolve the issue.