react-native-router icon indicating copy to clipboard operation
react-native-router copied to clipboard

Import error

Open AbrahamAlcaina opened this issue 9 years ago • 3 comments

Hi, When I try to use but I receive an error in the import

ERROR in ./~/react-native-router/index.js
Module parse failed: /Users/abraham/Documents/git/QuestionAnswersJS/node_modules/react-native-router/index.js Line 7: Unexpected token {
You may need an appropriate loader to handle this file type.
| var NavBarContainer = require('./components/NavBarContainer');
| 
| var {
|   StyleSheet,
|   Navigator,
 @ ./src/app/routes.jsx 21:25-55

Anybody have this issue? this is my code

import React from 'react-native';
import Router from 'react-native-router';
import ThemesPage from '../themes/pages/themesPage';

const firstRoute = {
    name: 'themes', 
    component: ThemesPage
}

class RouterApp extends React.Component{
    constructor(...args){
        super(...args)
    }
    render(){
        return (
            <Router {...this.props} firstRoute={firstRoute} />
            );
    }
}
export default Router;

AbrahamAlcaina avatar May 12 '15 15:05 AbrahamAlcaina

Do you use babel-loader? I got this same error and changed my exclude option for babel-loader to:

exclude: [
                    /\/react-native\//,
                    /\/react-native-router\/node_modules/
                ]

And I've got it working now.

jeremiahrhall avatar Jun 05 '15 20:06 jeremiahrhall

My solution was to include my 3rd-party libraries that need transformation with babel. react-native-router uses es6 syntax, so you will need to transform the code before it is bundled.

 module: {
    loaders: [
      {test: /\.js$/, include: [
        path.resolve(__dirname, 'js'),
        path.resolve(__dirname, 'node_modules/react-native-router'),
    ], loaders: ['babel?stage=0&blacklist=validation.react']},
    ]
  }

emilmork avatar Sep 15 '15 18:09 emilmork

@emilmork's answer should really be done in the packaging of this module. Shouldn't be shipped in jsx form.

braco avatar Oct 27 '15 19:10 braco