I'm using Webpack and React to build a simple Shopping Cart for a webshop. For some reason I get this error when I add my add to cart function to my .js file:
ERROR in ./js/views/Cart.js
Module build failed: SyntaxError: Unexpected token
And it points to var productID in my js code.
My Cart.js looks like:
import React, { Component } from 'react';
export default class Cart extends Component {
render() {
return (
<div className='Cart' id='Cart'>
<iframe src="./logo.pdf" width="425" height="425"></iframe>
$("#addit").click(function(){
var productId = $("#productId").val();
var productName = $("#productName").val();
var productQuantity = $("#productQuantity").val();
var data = {
'product_id': productId,
'product_name': productName,
'quantity': productQuantity
};
$.post("/cart/add", data, showDone);
});
var showDone = function() {
/* Make something happen here*/
}
</div>
);
}
}
My Webpack config is:
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?$/,
include: [
path.resolve(__dirname, "app")
],
loaders: ["react-hot", "babel-loader"],
},
{
test: /\.html$/,
loader: "file?name=[name].[ext]",
}
],
},
}
What is wrong with my code that is causing this error?