2

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.

2 Answers 2

5

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"
  ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

Added the .babelrc, and after I put "use babel" at the top of the files that have the import statements, it started to work. Thanks.
0

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?

10 Comments

No, not using a tool. According to the following page, the import statement should work in ES6 developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… I tried changing it to the code you suggested, but it then gives errors elsewhere in the imported component's code that use similar import syntax - so unfortunately that doesn't seem like it'll be a solution.
What I'm saying is 'import' is ES6 and must be translated into another syntax for React Native to be happy. Are the subsequent errors possibly getting you closer to a fix?
Furthermore, I just confirmed this syntax in my own test project produces the same error as you have reported.
Oh I see. I changed all the import statements to the syntax you suggested, and now it's complaining about the export statements, which look like the following: export default RadioButtons; export { SegmentedControls }; export { RadioButtons } I was going to change them to something like module.exports = Item; but I'm not sure what to do with the "default" export line.
Try shoving the source through Babel directly first. That might help.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.