admin管理员组文章数量:1416051
I am new to react. I a encountering an weired error and this leaves me perplexed! To my understanding nothing wrong in the syntax in index.jsx which is given below.
> 7 | <div>
| ^
My index.js is
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
render() {
return (
<div>
<p>Hi Russell!!</p>
</div>
);
}
}
ReactDOM.render( <App/>, document.getElementById('app'))
My package.json is
const webpack = require('webpack');
const path = require('path');
var APP_DIR = path.resolve(__dirname, 'src/client/app');
var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var config = {
entry: APP_DIR + '/index.jsx',
output: {
path: BUILD_DIR,
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?/,
include: APP_DIR,
loader: 'babel-loader'
}
]
}
}
module.exports = config;
I have reviewed every possible part of this. In spite of this, I am not able to figure out what is wrong. It still throws me the error. Any help on how to debug this?
The error pops up when I try to run
webpack -d
If I start by
npm run serve
The browser opens without rendering anything on the page. This leaves me in
Many thanks in advance.
I am new to react. I a encountering an weired error and this leaves me perplexed! To my understanding nothing wrong in the syntax in index.jsx which is given below.
> 7 | <div>
| ^
My index.js is
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
render() {
return (
<div>
<p>Hi Russell!!</p>
</div>
);
}
}
ReactDOM.render( <App/>, document.getElementById('app'))
My package.json is
const webpack = require('webpack');
const path = require('path');
var APP_DIR = path.resolve(__dirname, 'src/client/app');
var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var config = {
entry: APP_DIR + '/index.jsx',
output: {
path: BUILD_DIR,
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?/,
include: APP_DIR,
loader: 'babel-loader'
}
]
}
}
module.exports = config;
I have reviewed every possible part of this. In spite of this, I am not able to figure out what is wrong. It still throws me the error. Any help on how to debug this?
The error pops up when I try to run
webpack -d
If I start by
npm run serve
The browser opens without rendering anything on the page. This leaves me in
Many thanks in advance.
Share Improve this question asked Jul 15, 2017 at 11:31 BussllerBussller 2,0116 gold badges42 silver badges52 bronze badges 1- I have solved this issue by adding, query: { – Bussller Commented Jul 15, 2017 at 11:44
2 Answers
Reset to default 3I encountered the same problem and solved it by adding a .babelrc file in the root folder.
After installing babel-preset-env and babel-preset-react I created the .babelrc file and set it by typing:
{ "presets" : [ "env", "react" ] }
Solved this issue, by adding the following to the webpack.config.js as follows,
/*Previous Code*/
query: {
presets: ['es2015', 'react']
}
/*Remaining closure of brackets*/
module.exports = exports;
However, I have a question, I had this added in my .bablerc as follows,
{
presets: ['es2015', 'react']
}
Why has that not been taken? Any suggestions?
本文标签: javascriptModule build failed SyntaxError Unexpected tokenStack Overflow
版权声明:本文标题:javascript - Module build failed: SyntaxError: Unexpected token - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745247748a2649635.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论