Syntax error: Unexpected token, expected { (1:7) , create-react-app

fgonzalez

I started a new react project using create-react-app boilerplate (https://github.com/facebook/create-react-app), and I'm getting the following error when trying to start the app, the reason is that I have created a folder called 'containers' where all the containers go, and I want to create an index file to export all of them from that directory, this way I can just reference the directory in order to import de components.

Like this:

import UserContainer from './containers/UserContainer'; //This work(but ugly) import { UserContainer } from './containers'; // This does not work

Basically this is the content of my index.js file inside the containers folder:

export UserContainer from './UserContainer';

And I'm getting the error Syntax error: Unexpected token, expected { (1:7),

this is the content of my package.json:

    {
  "name": "user-management1",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "install": "^0.11.0",
    "npm": "^6.0.0",
    "react": "^16.3.2",
    "react-dom": "^16.3.2",
    "react-redux": "^4.2.1",
    "react-router-dom": "^4.2.2",
    "react-router-redux": "^5.0.0-alpha.4",
    "react-scripts": "1.1.4",
    "redux": "^3.5.2"
  },
  "scripts": {
    "lint": "eslint src",
    "lint:fix": "npm run lint -- --fix",
    "lint:css": "stylelint \"src/**/*.{css,less,scss,sss}\"",
    "start": "npm run lint:fix && react-scripts start & npm run apiserver",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "apiserver": "json-server --watch --port 4000 api/db.json"
  },
  "devDependencies": {
    "bulma": "^0.7.1",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-loader": "^1.7.1",
    "eslint-plugin-css-modules": "^2.7.1",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^6.10.3",
    "json-server": "^0.12.2"
  }
}

I start the app using 'react-scripts'. The problem seems related to babel?, do I need to start the app using babel-node?, or add any presets anywhere? I thought using this boilerplate babel was already configured to start coding in ES6.

Please help

Dario

You are basically re-exporting a module (that is adding another module’s exports to those of the current module). In order to make the named export UserContainer of module ./UserContainer the default export of current module you should write:

export { default as UserContainer } from './UserContainer'

Check this link for a complete reference

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

React — Syntax error: Unexpected token, expected ;

Syntax error: Unexpected token, expected ,

Syntax Error: Unexpected token, expected " , "

Type assertion via "as" keyword in a new create-react-app project results in `Parsing error: Unexpected token, expected ";"`

React Syntax Error: Unexpected Token at =

ReactJs TypeScript : Syntax error: Unexpected token, expected ;

React: Parsing error: Unexpected token, expected "("

React: Parsing error: Unexpected token, expected "..."

React JS : Parsing error: Unexpected token, expected ";"

Parsing error: Unexpected token, expected "," react

Syntax Error in Angular App: Unexpected token <

Syntax error: Unexpected token { on executing a TS app

Syntax error: Unexpected token in react project

Unexpected Token Syntax Error In If Statement With React Hooks

Syntax error with Electron and React: unexpected token

Syntax Error Unexpected Token, React Native

React - unexpected token, expected ;

React - Unexpected Token, expected }

Unexpected token, expected "," react

Unexpected token, expected "..." React

expression expected and Syntax error: Unexpected token jsx nextjs

Parsing error: unexpected token, expected "," and my react app is not showing up in browser. HELP PLEASE

Syntax error unexpected token '>'

material-ui in reactjs - @withStyles(styles) in react app giving Syntax error: Unexpected token > @withStyles(styles)

Syntax error on token ";", ,expected

Firebase and Create React Gives 'Unexpected token <' Error

Error: Unexpected token punc «)», expected punc «,» while minifying angularjs app

React native build error: Unexpected > token punc «:», expected punc «,» in file

React component constructor (Parsing error: Unexpected token , expected "}")