question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

misleading error message: configuration.module.rules[].exclude

See original GitHub issue

Bug report

What is the current behavior? misleading error message: configuration.module.rules[].exclude All other config property is removed here for clarity.

When I use string for exclude

  • config
// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: 'node_modules',
        use: [
          {
            loader: 'babel-loader'
          }
        ]
      }
    ]
  }
};
  • error message
## error
✖ 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module.rules[0].exclude should be one of these:
   RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? } | [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
   -> One or multiple rule conditions
   Details:
    * configuration.module.rules[0].exclude should be an instance of RegExp
    * configuration.module.rules[0].exclude: The provided value "node_modules" is not an absolute path!
    * configuration.module.rules[0].exclude should be an instance of function
    * configuration.module.rules[0].exclude should be an array:
      [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
    * configuration.module.rules[0].exclude should be an object.
    * configuration.module.rules[0].exclude should be an array:
      [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]

If I use array of string for exclude

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

  • error message
✖ 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module.rules[0].exclude should be one of these:
   RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? } | [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
   -> One or multiple rule conditions
   Details:
    * configuration.module.rules[0].exclude should be an instance of RegExp
    * configuration.module.rules[0].exclude should be a string.
    * configuration.module.rules[0].exclude should be an instance of function
    * configuration.module.rules[0].exclude[0] should be an instance of RegExp
    * configuration.module.rules[0].exclude[0]: The provided value "node_modules" is not an absolute path!
    * configuration.module.rules[0].exclude[0] should be an instance of function
    * configuration.module.rules[0].exclude[0] should be an array:
      [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
    * configuration.module.rules[0].exclude[0] should be an object.
    * configuration.module.rules[0].exclude should be an object.
    * configuration.module.rules[0].exclude[0] should be an instance of RegExp
    * configuration.module.rules[0].exclude[0]: The provided value "node_modules" is not an absolute path!
    * configuration.module.rules[0].exclude[0] should be an instance of function
    * configuration.module.rules[0].exclude[0] should be an array:
      [RegExp | string | function | [(recursive)] | object { and?, exclude?, include?, not?, or?, test? }]
    * configuration.module.rules[0].exclude[0] should be an object.

If the current behavior is a bug, please provide the steps to reproduce.

  1. use below config and run webpack-dev-server --config webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: ['node_modules'],
        use: [
          {
            loader: 'babel-loader'
          }
        ]
      }
    ]
  }
};

What is the expected behavior?

string should be removed from allowed object in error message.

Other relevant information: webpack version: ^4.29.6 Node.js version: 8.11.1 Operating System: ubuntu 18.04 webpack-dev-server: ^3.2.1

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vankopcommented, Oct 13, 2019

I can suggest to add extra info, e.g.

{
    "format": "absolutePath",
    "type": "string"
}

will produce string (absolute path) or absolute path string. Same for

{
    "format": "phone",
    "type": "string"
}

will produce phone string

UPD: we need to use https://github.com/epoberezkin/ajv#api-addformat instead of addKeyword

0reactions
alexander-akaitcommented, Oct 9, 2019

need add test case to avoid problem in future

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to use exclude in rule (error thrown) - webpack 2
I get an error for the following rule when I attempt to exclude. But no matter what valid condition I put in exclude...
Read more >
Module | webpack - JS.ORG
It's possible to configure all generators' options in one place with a module.generator . webpack.config.js module.exports = { module: { generator: { asset: ......
Read more >
webpack/webpack - Gitter
I get an error for the following rule when I attempt to exclude. But no matter what valid condition I put in exclude...
Read more >
Configuring Jest
This config option lets you customize where Jest stores that cache data on disk. clearMocks [boolean]​. Default: false. Automatically clear mock ...
Read more >
Configuration | Stylelint
Stylelint expects a configuration object. ... You must explicitly configure each rule to turn it on. ... The report is considered to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found