meteors
meteors

Reputation: 1827

Using decorators in React Native, can't find variable: require

I'm trying to use decorators in my RN project:

Following is my package.json file:

{
  "name": "testApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "autobind-decorator": "^1.3.3",
    "babel-core": "^6.7.4",
    "babel-loader": "^6.2.4",
    "babel-plugin-transform-class-properties": "^6.6.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-runtime": "^6.6.0",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-react-native": "^1.5.6",
    "babel-preset-stage-0": "^6.5.0",
    "babel-runtime": "^6.6.1",
    "react": "^0.14.8",
    "react-native": "^0.22.2",
    "webpack": "^1.12.14"
  }
}

and this is my .babelrc:

{
  "plugins": [
    "transform-runtime",
    "transform-decorators-legacy",
    "transform-class-properties"
  ],
  "presets": ["es2015", "react", "stage-0", "react-native"]
}

I'm getting error stating ReferenceError: Can't find variable: require . I tried many post but couldn't get any solution. I created new RN Project using react-native init testApp

Upvotes: 0

Views: 1053

Answers (1)

meteors
meteors

Reputation: 1827

Got it fixed error was because of order of presets: I removed all other presets and changed presets to just "react-native" and everything's working now.

Upvotes: 1

Related Questions