N
N
Nikita Shchypylov2018-03-13 01:12:43
React
Nikita Shchypylov, 2018-03-13 01:12:43

Why doesn't webpack see packages from devDependencies?

Previously, I always installed packages in the general config, now I decided to throw them in devDependencies, but it started to give an error:
My package.json:

{
  "name": "aviasales_test",
  "version": "1.0.0",
  "main": "index.js",
  "author": "Nikita Shchypylov <[email protected]>",
  "license": "MIT",
  "dependencies": {
    "webpack": "^4.1.1",
    "webpack-cli": "^2.0.11",
    "webpack-dashboard": "^1.1.1"
  },
  "scripts": {
    "build": "webpack"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.0.6",
    "react": "^16.2.0",
    "react-dom": "^16.2.0"
  }
}

webpack.config.json:
const path = require("path");
const HtmlWebPackPlugin = require("html-webpack-plugin");

module.exports = {
  entry: ["./src/index.js"],
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].js"
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["env"]
          }
        }
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader"
          }
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: "./public/index.html",
      filename: "./index.html"
    })
  ]
};

Result :
ERROR in multi ./src/index.js
Module not found: Error: Can't resolve 'babel-loader' in '/Users/nikulio/Documents/work/react/aviasales_test'
@ multi ./src/index. js

How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Epifanov, 2018-03-13
@Nikulio

probably there were some errors when installing babel. try reinstalling all the packages, run npm cache clean
the working config, tried the configuration at home - it all worked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question