Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does webpack need an empty extension

I'm trying to figure out why webpack requires this empty extension.

Inside resolve.extensions there's always this kind of configuration:

extensions: ['', '.js', '.jsx']

Why can't it be just this:

extensions: ['.js', '.jsx']
like image 903
Pepijn Avatar asked May 30 '16 15:05

Pepijn


2 Answers

In a newer Webpack Version you can't use an empty string. It says:

Getting error: configuration.resolve.extensions[0] should not be empty.

You have to use extensions: ['.js', '.jsx'] or extensions: ['*', '.js', '.jsx'].

Issue: https://github.com/webpack/webpack/issues/3043

like image 168
Robin Wieruch Avatar answered Oct 11 '22 14:10

Robin Wieruch


From the documentation:

Setting this option will override the default, meaning that webpack will no longer try to resolve modules using the default extensions. If you want modules that were required with their extension (e.g. require('./somefile.ext')) to be properly resolved, you must include an empty string in your array. Similarly, if you want modules that were required without extensions (e.g. require('underscore')) to be resolved to files with “.js” extensions, you must include ".js" in your array.

In other words, if you didn't include the empty string and required a module as ./foo.js, webpack would look for ./foo.js.js and ./foo.js.jsx instead.

like image 22
Felix Kling Avatar answered Oct 11 '22 15:10

Felix Kling