Search code examples
pathwebpackwebpack-2

Webpack2 cannot resolve: config.context absolute path


I am trying to run my webpack config file (see below), but I am still getting certain type of errors that reffers to a paths I use in my webpack settings:

 - config.context 
 - config.module.rules
 - config.output

My idea was, that I set up my config.context path absolutely (as it is written in docs), otherwise my webpack.config files reffers to node_modules in parents directory. But still, when I run webpack -w --env.dev command, it throws following errors:

enter image description here

It seems to me, that config.context cant handle absolute path as it should. Any help how to set up paths correctly? Thank you!

My webpack.config.js:

var path = require('path');
var webpack = require('webpack');
var ExtractText = require('extract-text-webpack-plugin');

    module.exports = function (env) {
      var project = {
        env: env.prod ? 'prod' : 'dev',
        jsBase: './routesMap/',
        cssBase: './src/css/'
      }

      var config = {
        context: path.resolve(__dirname),
        entry: {
          'routesMap': project.jsBase + 'main.js'
        },
        output: {
          path: path.join(__dirname, '/dist'),
          filename: '[name].js'
        },
        plugins: [
          new ExtractText({
            filename: 'styles.min.css',
            disable: false,
            allChunks: true
          })
        ],
        module: {
          rules: [
            {
              test: /\.js$/,
              loader: 'babel-loader',
              include: path.join(__dirname, '/routesMap'),
              exclude: /node_modules/,
              query: {
                cacheDirectory: true,
                presets: ['es2015'],
                plugins: ["transform-runtime"]
              }
            }
          ]
        }
      };

      return config;
    }

Solution

  • That's an issue with the latest webpack version. Try using uppercase drive letters in shell, e.g. C:/ instead c:/.

    More info https://github.com/webpack/webpack/issues/4530.