ERROR in Cannot find module 'babel-core'. using react.js, webpack, and express server

95,642

Solution 1

You should install babel-loader and babel-core as dev-dependency while npm install.

npm install babel-core babel-loader --save-dev

Solution 2

For those wanting to use babel-loader 8+: it requires Babel 7.x,, which is to be installed as the '@babel/core' package instead of 'babel-core'. In other words, run:

npm install --save-dev @babel/core

Solution 3

I just meet this error, and solved by installing babel-core. But the interesting is I found babel-core does exist in babel-loader's peerDependencies.

https://github.com/babel/babel-loader/blob/master/package.json

Why peerDependecies not install automatically, after a few searching work I found this in npm blog.

peerDependencies will not automatically install anymore.

Solution 4

Adding to @Chetan's answer on this thread:

I ran into this issue today while following through Dr. Axel Rauschmayer's book here. Per book, babel-loader should download babel-core as well. However this is not the case when I tried it out. I think this relates to @theJian's answer.

Since the original package.json already lists babel-loader as dependency, running the following command resolved the error.

npm install babel-core --save-dev

Solution 5

npm install babel-register

This can solve your issue. Additionally, add babelrc .babelrc { "presets" : ["es2015", "react"] }

Share:
95,642

Related videos on Youtube

Richard Bustos
Author by

Richard Bustos

Love everything that has to do with coding

Updated on October 21, 2020

Comments

  • Richard Bustos
    Richard Bustos over 3 years

    Whenever I run webpack in the terminal I get:

    Hash: efea76b1048c3a97b963
    Version: webpack 1.12.13
    Time: 33ms
        + 1 hidden modules
    
    ERROR in Cannot find module 'babel-core'
    

    Here is my webpack.config.js file

    module.exports = {
      entry: './app-client.js',
      output: {
        filename: 'public/bundle.js'
      },
      module: {
        loaders: [
          {
            exclude: /(node_modules|app-server.js)/,
            loader: 'babel'
          }
        ]
      }
    }
    

    package.json

    {
      "name": "react",
      "version": "1.0.0",
      "description": "React polling app",
      "main": "app-client.js",
      "dependencies": {
        "babel-loader": "^6.2.2",
        "bootstrap": "^3.3.6",
        "express": "^4.13.4",
        "react": "^0.14.7"
      },
      "devDependencies": {},
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "",
      "license": "ISC"
    }
    
  • andilabs
    andilabs over 6 years
    worked like a charm! rember to add it to your packag.json to avoid facing this problem again. Running npm install with flag -S wiil do the job.
  • Eric Hepperle - CodeSlayer2010
    Eric Hepperle - CodeSlayer2010 over 6 years
    Why? Can you give some explanation as to why this would work?
  • pguardiario
    pguardiario over 5 years
    I'm still getting: Error: Cannot find module '@babel/core' babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'
  • Brian Underwood
    Brian Underwood over 5 years
    It seems like loader v8 needs core v7, but core v7 currently just has a beta release, which seems like an oversight from the maintainers. I manually specified 7.1.5 for babel-loader (the latest version that is out right now) and I'm off and running
  • CounterFlame
    CounterFlame about 5 years
    Then I guess you aren't using babel-loader 8+. I answered this for people who happen to be upgrading/starting a new project but don't realize why it isn't working because of package rename. No need to downvote while it's clearly stated what version it applies to.