Pedram
Pedram

Reputation: 7879

Error on import statement in JavaScript/React Native code

I'm trying to incorporate a React component for radio buttons in my iOS app that's written in React Native, however I get an error when trying to import the component using the method that the author specified.

I first installed the component in the root directory of the app's XCode project/source code using the following statement:

npm i -S react-native-radio-buttons

Everything looked like it went through fine, so I incorporated the code for the component into the JS file for the screen that would use it, but I get an error on the very first line (which contains the import statement).

The import statement goes like this:

import { RadioButtons } from 'react-native-radio-buttons'

And the error is:

Uncaught SyntaxError: Unexpected reserved word

As far as I can tell, that should be an acceptable way of doing things in ES6. If anyone could tell me why this would happen, I'd be grateful. Thanks in advance.

Upvotes: 2

Views: 3089

Answers (2)

Arnaud Rinquin
Arnaud Rinquin

Reputation: 4306

react-native-radio-buttons author here,

I assumed everybody was using Babel with ES6 features enabled. I should add that to the README.

Edit: instruction and example .babelrc added to 0.4.2

Please try add this .babelrc file to your project root, as the provided example does:

{
  "whitelist": [
    "es6.modules"
  ]
}

Upvotes: 5

xanadont
xanadont

Reputation: 7604

Are you using a tool to translate from ES6? "import" is not going to work. Have you tried:

var RadioButtons = require('react-native-radio-buttons'); 

instead?

Upvotes: 0

Related Questions