React npm run build 오류 [module build failed: Syntax Error: Unexpected token(6:4)]

오류 메시지
ERROR in ./src/index.js
Module build failed: SyntaxError: Unexpected token (6:4)

구성 정보 있음
package.json
{
  "name": "react-xipiker-v1",
  "version": "1.0.0",
  "description": "react-xipiker-v1",
  "main": "index.js",
  "scripts": {
    "build": "webpack --config ./build/webpack.dev.config.js",
    "start": "webpack-dev-server --config ./build/webpack.dev.config.js --color --progress"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "webpack": "^3.10.0",
    "webpack-dev-server": "^2.9.7"
  },
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-router-dom": "^4.3.1"
  }
}

webpack.dev.config
const path = require('path')

module.exports = {
    entry: path.join(__dirname, '../src/index.js'),
    output: {
        path: path.join(__dirname, '../dist'),
        filename: 'bundle.js'
    },
    module: {
        rules: [{
            test: /\.js$/,
            use: ['babel-loader?cacheDirectory=true'],
            exclude: path.resolve(__dirname, 'node_modules')
        }],
    },
    devServer: {
        port: 8080,
        contentBase: path.join(__dirname, './dist'),
        historyApiFallback: true,
        host: '127.0.0.1'
    }
}

해결 방법
프로젝트 루트 디렉터리에 새로 만듭니다.babelrc
{
  "presets": [
    "react",
    "es2015"
  ]
}

좋은 웹페이지 즐겨찾기