이 오류를 해결하는 방법을 찾고 있었지만 수정하지 못했습니다. 내가 찾은 대부분의 대답은 바로 바벨을 세우는 것을 다루지 만, 나는 그것이 꼭해야만하는 것처럼 그것을 설정했다고 믿습니다. 내 프로젝트에서 React를 사용하기 위해 Webpack을 사용하고 있습니다.'잡히지 않은 SyntaxError : 예기치 않은 토큰 가져 오기'문제를 해결하는 방법?
내 웹팩 설정 파일은 다음과 같습니다
const path = require('path');
module.exports = {
context: __dirname + "/app",
entry: {
javascript: "./js/app.js",
html: "./index.html",
},
output: {
filename: "app.js",
path: __dirname + "/dist",
},
resolve: {
extensions: ['', '.js', '.jsx', '.json'],
root: path.resolve(__dirname, './app/js'),
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: ["react-hot", "babel-loader"],
},
{
test: /\.html$/,
loader: "file?name=[name].[ext]",
},
{ test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" }
],
},
}
내 index.html을은 다음과 같습니다
<html>
<head>
<title>React</title>
<meta charset="utf-8" />
<style>
* {
margin: 0;
padding: 0;
font-size: 18px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-weight: normal;
}
body {
background: #ededef;
}
#app,
.Info {
max-width: 600px;
padding: 40px;
margin: 0 auto;
position: relative;
}
hr {
border: 0;
border-top: 1px solid #ddd;
margin: 20px 0;
}
</style>
</head>
<body>
<div id="app"></div>
<script src="./js/app.js"></script>
</body>
</html>
내 JS 파일 app.js.에 import React from 'react';
과 반응로드 할 때 내가 오류가 발생 필요한 바벨 패키지를 설치했습니다. 내 루트 폴더에 .babelrc 파일이 있습니다. 이 오류의 원인은 무엇입니까?
편집
내 .babelrc 파일은 다음과 같습니다
{
"presets": [
"es2015",
"react"
]
}
당신이 파일을 .babelrc 표시 할 수 있습니다 : 그것은 같은 디렉토리에의로합니다 (
file-loader
구성한과) 방금 복사 가져옵니다index.html
때문에, 다음에<src>
태그를 변경해야? –이것이 당신의 오류에 영향을 줄지 모르지만 webpack.config 파일의 "html :"./index.html "엔트리 포인트는 무엇입니까? webpack의 엔트리 포인트는 js 번들을 만드는 데 사용되지만, 여기서는 012.htm 파일을 가리키고 있습니다. – ryandrewjohnson
@MayankShukla.babelrc – feners