0

i am creating a getting started application with react. I am on the first phase where i am printing hello world, which keeps throwing error.

Package.json.

{
  "name": "react-poc",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "npm run build",
    "build": "webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot",
    "build:prod": "webpack -p && cp src/index.html dist/index.html"
  },
  "keywords": [
    "reactjs"
  ],
  "author": "Ankur",
  "license": "MIT",
  "dependencies": {
    "react": "^16.4.1",
    "react-dom": "^16.4.1"
  },
  "devDependencies": {
    "babel-loader": "^7.1.4",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "webpack": "^4.12.0",
    "webpack-cli": "^3.0.8",
    "webpack-dev-server": "^3.1.4"
  }
}

webpack.config.js

var path = require('path'),
    DIST_DIR = path.resolve(__dirname,"dist"),
    SRC_DIR = path.resolve(__dirname,"src");

var config ={
    entry: SRC_DIR + "/app/index.js",
    output: {
        path:DIST_DIR +  "/app",
        filename:"bundle.js",
        publicPath: "/app/"
    },
    module: {
        rules:[
            {
                test: /.jsx?$/,
                loader: "babel-loader",
                exclude:/node_modules/,
                include:SRC_DIR,
                query:
                {
                    presets:["react","es2015","stage-2"]
                }
            }
        ]
    }
};

module.exports = config;

Below is the error that i get after npm start

ERROR in ./src/app/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module 'babel-core'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (C:\PracticeCode\ReactPOC\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object.<anonymous> (C:\PracticeCode\ReactPOC\node_modules\babel-loader\lib\index.js:3:13)
    at Module._compile (C:\PracticeCode\ReactPOC\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (C:\PracticeCode\ReactPOC\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at loadLoader (C:\PracticeCode\ReactPOC\node_modules\loader-runner\lib\loadLoader.js:13:17)
    at iteratePitchingLoaders (C:\PracticeCode\ReactPOC\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
    at runLoaders (C:\PracticeCode\ReactPOC\node_modules\loader-runner\lib\LoaderRunner.js:362:2)
    at NormalModule.doBuild (C:\PracticeCode\ReactPOC\node_modules\webpack\lib\NormalModule.js:282:3)
    at NormalModule.build (C:\PracticeCode\ReactPOC\node_modules\webpack\lib\NormalModule.js:429:15)
    at Compilation.buildModule (C:\PracticeCode\ReactPOC\node_modules\webpack\lib\Compilation.js:369:10)
    at moduleFactory.create (C:\PracticeCode\ReactPOC\node_modules\webpack\lib\Compilation.js:724:12)
    at factory (C:\PracticeCode\ReactPOC\node_modules\webpack\lib\NormalModuleFactory.js:405:6)
    at hooks.afterResolve.callAsync (C:\PracticeCode\ReactPOC\node_modules\webpack\lib\NormalModuleFactory.js:155:13)
    at AsyncSeriesWaterfallHook.eval [as callAsync] (eval at create (C:\PracticeCode\ReactPOC\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesWaterfallHook.lazyCompileHook [as _callAsync] (C:\PracticeCode\ReactPOC\node_modules\tapable\lib\Hook.js:35:21)
    at resolver (C:\PracticeCode\ReactPOC\node_modules\webpack\lib\NormalModuleFactory.js:138:29)
    at process.nextTick (C:\PracticeCode\ReactPOC\node_modules\webpack\lib\NormalModuleFactory.js:342:9)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.

What is the thing that i am doing wrong here.

1 Answer 1

3

Install babel-core as your dev dependency and it should work:

npm install babel-core --save-dev

Credits:

  1. Cannot find module 'babel-core'
  2. ERROR in Cannot find module 'babel-core'. using react.js, webpack, and express server
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.