0

I have set up a React environment with webpack and babel. However, when I run webpack-dev-server --progress --colors, I get error like this:

ERROR in multi (webpack)-dev-server/client?http://localhost:8080 E:/src/index.js

Module not found: Error: can't resolve 'E:\src/index.js' in 'E:\personal_projects\web-site-name'

...

(2:1) Unknown word

1: var url = require("url");
   ^

My webpack.config.js file is this:

var webpack = require('webpack');
var path = require('path');

var BUILD_DIR = path.resolve(__dirname, '/public');
var APP_DIR = path.resolve(__dirname, '/src');

var config = {
  entry: APP_DIR + '/index.js',
  output: {
    path: BUILD_DIR,
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['env']
          }
        }
      },
      {
        test: /(\.css$)/,
        loaders: ['style-loader', 'css-loader', 'postcss-loader']
      },
      {
        loader: 'postcss-loader',
        options: {
          plugins: () => [require('autoprefixer')]
        }
      }
    ]
  }
};

module.exports = config;

I think there is some problem with babel and it compiling my index.js to my bundle.js file. Any advice on this?

1 Answer 1

1

You either need to use path.join or remove your slashes, e.g.

path.resolve(__dirname, '/src');

and other lines using resolve should be

path.resolve(__dirname, 'src');

or

path.join(__dirname, 'src');

or even

path.join(__dirname, '/src');

Your usage of .resolve passes an absolute path /src, meaning that the first argument is essentially discarded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.