Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack 2 cannot resolve empty extensions

So in webpack 2 when requiring/import a file import file from './file';

I got the following message:

You may need an appropriate loader to handle this file type.

This is because when requiring a file in [email protected] I used to have:

resolve: { extensions: ['', '.js'] ...

But it seems this is no longer accepted in webpack@2

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.resolve.extensions[0] should not be empty.

I have read migrating guide but I couldn't find it.

My loaders are as simple as that:

module: {
  rules: [
    {
      test: /\.js$/,
      exclude: /node_modules/,
      use: 'babel-loader'
    }
  ]
}

How do I fix it?

Thanks

like image 632
locropulenton Avatar asked Feb 06 '17 13:02

locropulenton


2 Answers

this has been modified now in webpack2

now you have to provide only

resolve: {extensions: ['.js', '.ts','jsx','tsx']}

based upon the code syntax you choose

and if you provide '' in the array it throws an error

configuration.resolve.extensions[0] should not be empty

you can also provide ['*'] if you want to match all files.

like image 147
prasanth shenoy Avatar answered Nov 15 '22 16:11

prasanth shenoy


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'] or extensions: ['*', '.js'].

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

like image 9
Robin Wieruch Avatar answered Nov 15 '22 18:11

Robin Wieruch