Paulos3000
Paulos3000

Reputation: 3545

BabelLoaderError: SyntaxError: Missing class properties transform

Getting the following message when I try to run my dev-server:

BabelLoaderError: SyntaxError: Missing class properties transform.

I've installed the class-properties babel plugin as you can see, and I have incorporated it into my .babelrc file:

.babelrc

{ "presets": ["es2015", "stage-2"],
  "plugins": ["transform-class-properties"]
}

But still won't render. If I remove this ES6 arrow function - add = (a, b) => a + b - it renders perfectly, but the class-properties plugin doesn't seem to be fixing it...

Would appreciate if anyone can spot what's going wrong.

package.json

{
  "name": "judo-heroes",
  "version": "1.0.0",
  "description": "Simple application to showcase how to achieve universal rendering and routing with React and Express.",
  "main": "src/server.js",
  "repository": "[email protected]:lmammino/judo-heroes.git",
  "scripts": {
    "start": "NODE_ENV=production node_modules/.bin/babel-node --presets 'react,es2015' src/server.js",
    "start-dev": "npm run start-dev-hmr",
    "start-dev-single-page": "node_modules/.bin/http-server src/static",
    "start-dev-hmr": "node_modules/.bin/webpack-dev-server --progress --inline --hot",
    "build": "NODE_ENV=production node_modules/.bin/webpack -p"
  },
  "author": "Luciano Mammino",
  "license": "MIT",
  "dependencies": {
    "babel-cli": "^6.11.4",
    "babel-core": "^6.13.2",
    "babel-loader": "^6.2.5",
    "babel-plugin-react-html-attrs": "^2.0.0",
    "babel-plugin-transform-es2015-arrow-functions": "^6.8.0",
    "babel-preset-es2015": "^6.13.2",
    "babel-preset-react": "^6.11.1",
    "babel-preset-react-hmre": "^1.1.1",
    "ejs": "^2.5.1",
    "express": "^4.14.0",
    "react": "^15.3.1",
    "react-dom": "^15.3.1",
    "react-redux": "^4.4.5",
    "react-router": "^2.6.1",
    "redux": "^3.6.0"
  },
  "devDependencies": {
    "babel-plugin-transform-class-properties": "^6.18.0",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-stage-2": "^6.18.0",
    "http-server": "^0.9.0",
    "react-hot-loader": "^1.3.0",
    "webpack": "^1.13.2",
    "webpack-dev-server": "^1.14.1"
  }
}

webpack.config.js

"use strict";

const debug = process.env.NODE_ENV !== "production";

const webpack = require('webpack');
const path = require('path');

module.exports = {
  devtool: debug ? 'inline-sourcemap' : null,
  entry: path.join(__dirname, 'src', 'app-client.js'),
  devServer: {
    inline: true,
    port: 3333,
    contentBase: "src/static/",
    historyApiFallback: {
      index: '/index-static.html'
    }
  },
  output: {
    path: path.join(__dirname, 'src', 'static', 'js'),
    publicPath: "/js/",
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      test: path.join(__dirname, 'src'),
      loader: ['babel-loader'],
      query: {
        cacheDirectory: 'babel_cache',
        presets: debug ? ['react', 'es2015', 'react-hmre'] : ['react', 'es2015']
      }
    }]
  },
  plugins: debug ? [] : [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
    }),
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({
      compress: { warnings: false },
      mangle: true,
      sourcemap: false,
      beautify: false,
      dead_code: true
    }),
  ]
};

Upvotes: 1

Views: 2434

Answers (1)

Paulos3000
Paulos3000

Reputation: 3545

Ok, I figured it out. I needed to include this in my .babelrc file:

{ "presets": ["es2015"] }

And also, I needed this in my webpack.config.js (specifically the stage-2 part):

presets: debug ? ['react', 'es2015', 'stage-2', 'react-hmre'] : ['react', 'es2015', 'stage-2']

Also note, I found the order the presets are declared in is important.

Hope this helps anyone who faces a similar problem.

Upvotes: 1

Related Questions