I have spent two days trying all the other stack overflow questions with simular problems but none were able to help. My babel loader looks correct in terms of i include both the presets and plugins, and its inside the module.
Problem: So my app loads but my imports fail to work giving me errors such as Uncaught SyntaxError: Unexpected token, or unexpected Identifier in the sources tab in crhome dev tools. If I delete the first import it will complain about the second import and so on.
Picture examples of the errors:
Below are the configuration files I have, I beleve there must be an issue with my webpack thats making babel not work correctly.
imports from one file:
import React from 'react';
import { Link } from "react-router";
import { LOAD_YMMTT_DATA } from "./../reducers/constants";
import {connect} from 'react-redux';
import { fetchYmmttData, getVisibleYmmttData } from "../reducers/ymmtt";
Webpack.config.js
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module.exports = {
context: path.join(__dirname, "src"),
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/main.js",
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['react', "env", "stage-2"],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties' ]
}
}
},
{ test: /\.css$/, loader: "style-loader!css-loader" },
{ test: /\.(jpe?g|png|gif|svg)$/i,
use: [{
loader: 'file-loader',
// options: {
// name: '[sha512].[ext]'
// }
},
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
optimizationLevel: 7,
interlaced:false
}
}]
}
],
},
output: {
path: path.join(__dirname, "src"),
filename: "main.min.js"
},
devServer: {
port: 3000,
historyApiFallback: true,
contentBase: './',
hot: true
}
};
Below is my package.json
{
"name": "react-mobx-todos",
"version": "1.0.0",
"description": "",
"proxy": "http://localhost:3001/",
"main": "main.js",
"scripts": {
"start": "webpack-dev-server --content-base src --inline --hot",
"dev-server": "json-server -p 8080 --watch db.json"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.2",
"history": "^1.17.0",
"json-server": "^0.12.1",
"mobx": "^2.7.0",
"mobx-react": "^3.5.9",
"nodemon": "^1.14.11",
"oracledb": "^2.0.15",
"react": "^15.2.1",
"react-dom": "^15.3.0",
"react-redux": "^5.0.7",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"redux": "^3.7.2",
"request": "^2.83.0",
"sequelize": "^4.32.2",
"sequelize-oracle": "^3.3.2-0.0",
"treemap": "^1.0.4"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^6.4.1",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.10.2",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.3.13",
"babel-preset-stage-2": "^6.24.1",
"body-parser": "1.18.2",
"css-loader": "^0.23.1",
"file-loader": "^1.1.6",
"history": "^1.17.0",
"image-webpack-loader": "^3.4.2",
"oracledb": "^2.0.15",
"react-addons-test-utils": "^15.3.0",
"style-loader": "^0.13.1",
"webpack": "^3.11.0",
"webpack-dev-server": "^1.14.1"
}
}
My babelrc
{
"presets": ['react', 'es2015', "stage-2"],
"plugins": ['react-html-attrs','transform-decorators-legacy', 'transform-class-properties']
}
Any help is appreaciated.