1

一切正常。我安装了 npm 模块simplewebrtc,但它停止了工作。

我得到的错误是未定义窗口:

webpack:///./node_modules/@andyet/simplewebrtc/node_modules/webrtc-adapter/src/js/adapter_core.js?:16
const adapter = Object(_adapter_factory_js__WEBPACK_IMPORTED_MODULE_0__["adapterFactory"])({window});
                                                                                            ^

ReferenceError: window is not defined
    at eval (webpack:///./node_modules/@andyet/simplewebrtc/node_modules/webrtc-adapter/src/js/adapter_core.js?:16:93)
    at Module../node_modules/@andyet/simplewebrtc/node_modules/webrtc-adapter/src/js/adapter_core.js (/Users/testmac/node/test-frontend/frontend-test/server.js:2505:1)
    at __webpack_require__ (/Users/testmac/node/test-frontend/frontend-test/server.js:21:30)
    at eval (webpack:///./node_modules/@andyet/simplewebrtc/module.js?:37:72)
    at Module../node_modules/@andyet/simplewebrtc/module.js (/Users/testmac/node/test-frontend/frontend-test/server.js:2493:1)
    at __webpack_require__ (/Users/testmac/node/test-frontend/frontend-test/server.js:21:30)
    at eval (webpack:///./app/src/components/common/calling/CallingSimple.js?:7:78)
    at Module../app/src/components/common/calling/CallingSimple.js (/Users/testmac/node/test-frontend/frontend-test/server.js:1500:1)
    at __webpack_require__ (/Users/testmac/node/test-frontend/frontend-test/server.js:21:30)
    at eval (webpack:///./app/src/routes.js?:36:99)

我应用了此链接中给出的解决方案,但它不起作用

我的 webpack.config.js 如下:

const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const ImageminPlugin = require('imagemin-webpack')
const imageminGifsicle = require('imagemin-gifsicle')
const imageminJpegtran = require('imagemin-jpegtran')
const imageminOptipng = require('imagemin-optipng')
const imageminSvgo = require('imagemin-svgo')

const server = {
  entry: ['@babel/polyfill', './app/src/server.js'],
  target: 'node',
  output: {
    path: __dirname,
    filename: 'server.js',
    globalObject: "this"
    // libraryTarget: "commonjs2"
  },
  module: {
    rules: [{
      test: /\.js$/,
      exclude: /node_modules/,
      use: {
        loader: 'babel-loader'
      }
    },
    {
      test: /\.(png|jpg|gif|svg)$/,
      loader: 'file-loader',
      options: {
        name: 'dist/assets/images/[name].[ext]'
      }
    },
    {
      test: /\.(css)$/,
      loader: 'file-loader',
      options: {
        name: '/dist/assets/css/[name].[ext]'
      }
    },
    // File loader used to load fonts
    {
      test: /\.(woff|woff2|eot|ttf|otf)$/,
      loader: 'file-loader',
      options: {
        name: '/dist/assets/fonts/[name].[ext]'
      }
    },
    {
      test: /\.scss$/,
      use: ExtractTextPlugin.extract({
        fallback: 'style-loader',
        use: ['css-loader', 'sass-loader']
      })
    }
    ]
  },
  plugins: [
    new ExtractTextPlugin({
      filename: 'dist/assets/css/style.bundle.css'
    }),
    new webpack.BannerPlugin({
      banner: '__isBrowser__ = false;',
      raw: false,
      include: /\.js$/
    })
  ]
}

const client = {
  entry: ['@babel/polyfill', './app/src/client.js'],
  output: {
    path: __dirname,
    filename: './dist/app.bundle.js',
    globalObject: "this"
  },
  devtool: 'source-map',
  module: {
    rules: [{
      test: /\.(png|jpg|gif|svg)$/,
      loader: 'file-loader',
      options: {
        name: '/dist/assets/images/[name].[ext]'
      }
    },
    {
      test: /\.(css)$/,
      loader: 'file-loader',
      options: {
        name: 'dist/assets/css/[name].[ext]'
      }
    },
    // File loader used to load fonts
    {
      test: /\.(woff|woff2|eot|ttf|otf)$/,
      loader: 'file-loader',
      options: {
        name: '/dist/assets/fonts/[name].[ext]'
      }
    },
    {
      test: /\.scss$/,
      use: ExtractTextPlugin.extract({
        fallback: 'style-loader',
        use: ['css-loader', 'sass-loader']
      })
    },
    {
      test: /js$/,
      exclude: /(node_modules)/,
      loader: 'babel-loader'
    }
    ]
  },
  plugins: [
    new ExtractTextPlugin({
      filename: 'dist/assets/css/style.bundle.css'
    }),
    new OptimizeCssAssetsPlugin(),
    new BundleAnalyzerPlugin(),
    new ImageminPlugin({
      bail: false,
      cache: true,
      imageminOptions: {
        plugins: [
          imageminGifsicle({
            interlaced: true
          }),
          imageminJpegtran({
            progressive: true
          }),
          imageminOptipng({
            optimizationLevel: 5
          }),
          imageminSvgo({
            removeViewBox: true
          })
        ]
      }
    })
  ]
}

module.exports = (env) => [server, client]

但是错误仍然存​​在。

4

0 回答 0