Ismael Celis
Ismael Celis

Reputation: 11

react.js and webpack 2, need a solution

I am doing a sample tutorial with create-react-app and webpack 2, but I am receiving this error:

enter image description here

This is my package.json:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-core": "^6.22.1",
    "babel-loader": "^6.2.10",
    "babel-preset-latest-minimal": "^1.1.2",
    "babel-preset-react": "^6.22.0",
    "css-loader": "^0.26.1",
    "html-loader": "^0.4.4",
    "json-loader": "^0.5.4",
    "node-sass": "^4.5.0",
    "raw-loader": "^0.5.1",
    "react-scripts": "0.8.5",
    "sass-loader": "^5.0.1",
    "style-loader": "^0.13.1",
    "svgo-loader": "^1.1.2",
    "webpack": "^2.2.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "dependencies": {
    "file-loader": "^0.10.0",
    "react": "^15.4.2",
    "react-dom": "^15.4.2",
    "react-router": "^3.0.2"
  }
}

My webpack.config.js:

module.exports = {
  context: __dirname,
  entry: {
    app: '../src/index.jsx', 

  },
  output: {
    path: './build',
    filename: 'app.js',
  },
  module: {
    loaders: [{
    test: /\.html$/,
    loader: 'html-loader',
    query: {
      minimize: true
    }
  },{
      test: /(\.jsx?)$/,
      loader: 'babel-loader',
      exclude: /(node_modules)/,
      query: {
        presets: ['latest-minimal', 'react'],
      }
    }, {
      test: /\.css$/,
      exclude: /(node_modules)/,
      use: ['style-loader', 'css-loader']
    },{
      test: /\.svg$/,
      use: [{
        loader: 'file-loader'
      }, {
        loader: 'svgo-loader',
        options: {
          plugins: [{
            removeTitle: true
          }, {
            convertColors: {
              shorthex: false
            }
          }, {
            convertPathData: false
          }]
        }
      }]
    }]
  }
}

And my index.jsx:

import React, { Component } from 'react';
import { render } from 'react-dom';

import App from './App.jsx';

render(<App />, document.getElementByClass('App'));

Upvotes: 0

Views: 809

Answers (3)

cstuncsik
cstuncsik

Reputation: 2786

If you still haven't found one I think this is pretty good

Upvotes: 0

Sagar Rabadiya
Sagar Rabadiya

Reputation: 4321

I have created a bolierplate which uses create-react-app and uses webpack 2 you can take configurations from there.

https://github.com/sagarrabadiya/react-boilerplate

Upvotes: 0

Alex L
Alex L

Reputation: 64

create-react-app was written for webpack 1. You have updated to webpack 2 which only came out a month ago. There are some syntax changes that break version 1 webpack.config.js files. Here is a migration guide:

https://webpack.js.org/guides/migrating/

Upvotes: 1

Related Questions