Hey I Have been trying to add @observer to my react component but this error occurs : Support for the experimental syntax 'decorators-legacy' isn't currently enabled
here are the steps I have taken:
1.npm install mobx --save
and npm i mobx mobx-react --save
tried using observable did not work
added
[ require(‘@babel/plugin-proposal-decorators’).default, { legacy: true } ],
didn't work so i removed it
Created .babelrc in at the root directory and added
{ "presets": ["react-native"], "plugins": [ [ "@babel/plugin-proposal-decorators", { "legacy": true } ] ] }
and still not working
Editing:
I did what you just said and same error:
when I npm start -- --reset-cache
, this appears on my terminal, maybe it might help:
Emitted 'error' event at:
at Server.WebSocketServer._onServerError (/Users/red/mApp/node_modules/ws/lib/WebSocketServer.js:82:50)
at Server.emit (events.js:202:15)
at emitErrorNT (net.js:1283:8)
at processTicksAndRejections (internal/process/next_tick.js:76:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node node_modules/react-native/local-cli/cli.js start "--reset-cache"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Package.json file
{
"name": "mapp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"@expo/vector-icons": "^10.0.2",
"babel-plugin-mobx-deep-action": "^1.6.1",
"jetifier": "^1.6.3",
"jsc-android": "241213.x.x",
"mobx": "^5.11.0",
"mobx-react": "^6.1.1",
"react": "16.8.3",
"react-native": "^0.59.10",
"react-native-background-fetch": "^2.6.0",
"react-native-background-geolocation": "^3.0.7",
"react-native-css-gradient": "^0.3.1",
"react-native-gesture-handler": "^1.3.0",
"react-native-ionicons": "^4.5.6",
"react-native-linear-gradient": "react-native-community/react-native-linear-gradient",
"react-native-maps": "^0.24.2",
"react-native-responsive-screen": "^1.2.2",
"react-native-svg": "^9.5.2",
"react-native-svg-transformer": "^0.13.0",
"react-native-vector-icons": "^6.5.0",
"react-native-vertical-tab-view": "^0.1.3",
"react-navigation": "^3.11.0",
"react-redux": "^7.1.0",
"redux": "^4.0.1"
},
"devDependencies": {
"@babel/core": "7.4.5",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/runtime": "7.4.5",
"babel-jest": "24.8.0",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.54.1",
"react-test-renderer": "16.8.3",
"redux-devtools": "^3.5.0"
},
"jest": {
"preset": "react-native"
}
}
You have to add plugin-proposal-decorators
in babel.config.js
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
};
Add "babel-preset-react-native": "4.0.0",
and reset cache