0

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'));
5
  • You're running React in Node, but you have to run the code in a browser. Commented Feb 12, 2017 at 6:35
  • You need to build the bundle using Webpack in node and then view the application in the browser. At the console, you need to run Webpack command to build and then run Webpack dev server. Commented Feb 12, 2017 at 8:37
  • The error gives me, after running the webpack command Commented Feb 12, 2017 at 16:08
  • check this repo i have created boilerplate which uses create-react-app structure and uses webpack 2 you can grab configs from there or add your components inside it. github.com/sagarrabadiya/react-boilerplate Commented May 2, 2017 at 13:22
  • also you need to eject from create-react-app if you want to customise all the behaviour.. ;) Commented May 2, 2017 at 13:23

3 Answers 3

1

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/

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.