Skip to content
Advertisement

Webpack Configuration Error – where is the bug?

I try to run “node index.js” and get the following error message:

ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.

  • configuration.module.rules[0] should be one of these: [“…” | object { compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, sideEffects?, test?, type?, use? }, …] -> A rule. Details:
    • configuration.module.rules[0].loader should be a non-empty string. -> A loader request.

Here is my webpack.config.js

    module.exports = {
  entry: [
    './main.js',
  ],
  output: {
    path: '/',
    filename: 'main-bundle.js',
  },
  module: {
    rules: [
      {
        test: /.jsx?$/,
        exclude: /node_modules/,
        loader: ['babel-loader'],
      },
      { test: /.css$/, loader: 'style-loader!css-loader' },
      { test: /.eot(?v=d+.d+.d+)?$/, loader: 'file-loader' },
      {
        test: /.(woff|woff2)$/,
        loader: 'url-loader',
        options: {
          prefix: 'font/',
          limit: '5000',
        },
      },
      {
        test: /.ttf(?v=d+.d+.d+)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          mimetype: 'application/octet-stream',
        },
      },
      {
        test: /.svg(?v=d+.d+.d+)?$/,
        loader: 'url-loader',
        options: {
          limit: '10000',
          mimetype: 'image/svg+xml',
        },
      },
    ],
  },
};

Please help me find the error, I’ve read the documentation and just can’t find it!

Advertisement

Answer

You need to pass the html in a string to res.end. Since you have multiple lines of html, you can use template-literals (note the backticks `..`) to make it easier.

Using template-literals you can define embedded expressions using ${expression} that will be concatenated into the resulting string. In your example this is used to set e.g. the hostname: ${os.hostname}:

res.end(`<html><head><title>Operating System Info</title></head><body><h1>Operating System Info</h1>
    <table>
        <tr><th>TMP Dir</th><td>${os.tmpdir()}</td></tr>
        <tr><th>Host Name</th><td>${os.hostname()}</td></tr>
        <tr><th>OS Type</th><td>${os.type()}</td></tr> 
        ${os.platform()}
        ${os.arch()} $os.release()}</td></tr>
        <tr><th>Uptime</th><td>${os.uptime()} ${util.inspect(os.loadavg())}</td></tr>
        <tr><th>Memory</th><td>total: ${os.totalmem()} free: ${freemem()}</td></tr>
        <tr><th>CPU's</th><td><pre>${util.inspect(os.cpus())}</pre></td></tr>
        <tr><th>Network</th><td><pre>${util.inspect(os.networkInterfaces())}</pre></td>,/tr>
        </table>
        </body></html>`);
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement