Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  185] [ 3]  / answers: 1 / hits: 37869  / 9 Years ago, tue, november 3, 2015, 12:00:00

webpack.config.js



module.exports = {
context: __dirname + /app,
entry: {
javascript: ./app.js,
html: ./index.html,
},
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
filename: app.js,
path: __dirname + /dist,
},
module: {
loaders: [
{
test: /.jsx?$/,
exclude: /node_modules/,
loader: babel-loader,
},
{
test: /.html$/,
loader: file?name=[name].[ext],
},
],
},
}


package.json



{
name: react-webpack-project,
version: 1.0.0,
description: ,
main: index.js,
scripts: {
test: echo Error: no test specified && exit 1
},
author: ,
license: ISC,
devDependencies: {
babel: ^6.0.15,
babel-core: ^6.0.20,
babel-loader: ^6.0.1,
file-loader: ^0.8.4,
webpack: ^1.12.2
},
dependencies: {
react: ^0.14.2
}
}


app/app.js



import React from react;
import Greeting from ./greeting;

React.render(
<Greeting name=World/>,
document.body
);


I have seen the exact same questions after searching around, but none of the answers seemed to apply to me. I am getting the following error when running webpack :



ERROR in ./app.js

Module build failed: SyntaxError: path/to/project/react-webpack-project/app/app.js: Unexpected token (5:2)





React.render(
<Greeting name=World/>,
document.body
);





I am not sure why I am getting this error still. I am guessing it has something to do with my webpack.config.js file, but not 100% what the problem is.


More From » node.js

 Answers
5

First of all: if you are using React v^0.14, you should render your code using React-Dom. https://www.npmjs.com/package/react-dom



Second, this should resolve your problem:
babel-loader jsx SyntaxError: Unexpected token


[#64518] Sunday, November 1, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deving

Total Points: 26
Total Questions: 94
Total Answers: 103

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;