React npm run buildエラー[Module build failed:SyntaxError:Unexpected token(6:4)]
5304 ワード
エラーメッセージ
既存の構成情報
package.json
webpack.dev.config
解決策
プロジェクトのルートディレクトリに新規作成します.babelrc
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"
]
}