react-native-router
react-native-router copied to clipboard
Import error
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;
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.
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's answer should really be done in the packaging of this module. Shouldn't be shipped in jsx form.