我收到一个错误无效的配置对象。已使用与API模式不匹配的配置对象初始化了Webpack

时间:2018-06-27 07:50:36

标签: webpack

我正在尝试使用WebRTC和React js创建视频通话网站,但是每次我web pack --progress -p我都不明白为什么会有问题

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module has an unknown property 'loaders'. These properties are valid:
   object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
   -> Options affecting the normal modules (`NormalModuleFactory`).
 - configuration.output.path: The provided value "./public" is not an absolute path!
   -> The output directory as **absolute path** (required).
 - configuration.resolve.extensions[0] should not be empty.
   -> A non-empty string

它显示上述错误

    import express from 'express';
    import path from 'path';
    import fs from 'fs';
    import http from 'http';
    import https from 'https';
    import sio from 'socket.io';
    import favicon from 'serve-favicon';
    import compression from 'compression';

    const app = express(),
      options = { 
        key: fs.readFileSync(__dirname + '/rtc-video-room-key.pem'),
        cert: fs.readFileSync(__dirname + '/rtc-video-room-cert.pem')
      },
      port = process.env.PORT || 3000,
      server = process.env.NODE_ENV === 'production' ?
        http.createServer(app).listen(port) :
        https.createServer(options, app).listen(port),
      io = sio(server);
    // compress all requests
    app.use(compression());
    app.use(express.static(path.join(__dirname, 'public')));
    app.use((req, res) => res.sendFile(__dirname + '/public/index.html'));
    app.use(favicon('./public/favicon.ico'));
    // Switch off the default 'X-Powered-By: Express' header
    app.disable('x-powered-by');
    io.sockets.on('connection', socket => {
      let room = '';
      const create = err => {
        if (err) {
          return console.log(err);
        }
        socket.join(room);
        socket.emit('create');
      };
      // sending to all clients in the room (channel) except sender
      socket.on('message', message => socket.broadcast.to(room).emit('message', message));
      socket.on('find', () => {
        const url = socket.request.headers.referer.split('/');
        room = url[url.length - 1];
        const sr = io.sockets.adapter.rooms[room];
        if (sr === undefined) {
          // no room with such name is found so create it
          socket.join(room);
          socket.emit('create');
        } else if (sr.length === 1) {
          socket.emit('join');
        } else { // max two clients
          socket.emit('full', room);
        }
      });
      socket.on('auth', data => {
        data.sid = socket.id;
        // sending to all clients in the room (channel) except sender
        socket.broadcast.to(room).emit('approve', data);
      });
      socket.on('accept', id => {
        io.sockets.connected[id].join(room);
        // sending to all clients in 'game' room(channel), include sender
        io.in(room).emit('bridge');
      });
      socket.on('reject', () => socket.emit('full'));
      socket.on('leave', () => {
        // sending to all clients in the room (channel) except sender
        socket.broadcast.to(room).emit('hangup');
        socket.leave(room);});
    });

此代码有些过时了,它创建于2018年1月,当时可以正常使用,但现在不行了。 另外,当我执行console.log(app.address()。port)时,它不显示端口

1 个答案:

答案 0 :(得分:1)

将选项加载程序更改为规则。为我解决了。希望这对某人有帮助。