W
W
Wasya UK2017-09-20 20:34:17
Bitrix24
Wasya UK, 2017-09-20 20:34:17

Why can't webpack resolve 'babel-loader'?

What could be wrong?
webpack.config.js

'use strict'

const path = require('path');

module.exports = {
  entry: './main.js',
  output: {
    filename: 'build.js'
  },
  module: {
    rules: [{
      loader: 'babel-loader',
      options: {
        presets: ['es2015']
      }
    }]
  },
  resolve: {
    modules: [
      'node_modules',
      path.resolve(__dirname, '/')
    ],
    extensions: [".js", ".json", ".jsx", ".css"]
  }
}

main.js
import React from 'react'
import ReactDOM from 'react-dom'
import Babel from 'babel'

const $header = document.getElementById('header');

class Navigation extends React.Component {
  render() {
    return (
      <nav>
        <a href="">1-link</a>
        <a href="">2-link</a>
        <a href="">3-link</a>
        <a href="">4-link</a>
        <a href="">5-link</a>
      </nav>
    );
  }
}

ReactDOM.render(<Navigation />, $header);

package.json
{
  "name": "reactjs",
  "version": "1.0.0",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "wasya1212",
  "license": "ISC",
  "description": "simple webpack react project",
  "dependencies": {
    "babel": "^6.23.0",
    "react": "^15.6.1",
    "react-dom": "^15.6.1"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^3.6.0",
    "webpack-dev-server": "^2.8.2"
  }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoly Kulikov, 2019-06-06
@it_pear_yurec

The option itself is called "Auto Redial".
Look here , ask support a question - they usually answer correctly and quickly enough. In addition, this question is probably already known and there is a ready-made solution.

W
Wasya UK, 2017-09-20
@dmc1989

Here are all the problems:
1. The atom terminal interfered with the installation of modules
2. The webpack configuration should be as follows:

module.exports = {
  entry: './main.js',
  output: {
    filename: 'build.js'
  },
  module: {
    rules: [{
      test: /\.js$/,
      use: {
        loader: 'babel-loader',
        options: {
          presets: ['es2015', 'react']
        }
      }
    }]
  },
  resolve: {
    modules: ['node_modules'],
    extensions: [".js", ".json", ".jsx", ".css"]
  }
}

J
Javid Askerov, 2017-09-20
@HalfBloodPrince

Judging by package.json, this is the latest version of webpack, and their documentation indicates this whole thing a little differently. Maybe this is the problem, try as indicated in the documentation:

module: {
  rules: [
    {
      test: /\.js$/,
      use: {
        loader: 'babel-loader',
        options: {
          presets: ['env']
        }
      }
    }
  ]
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question