feross/simple-peer

Webpack v5.x.x needs extra configuration than other webpack <5 projects

r01010010 opened this issue · 1 comments

What version of this package are you using?
9.9.3

What operating system, Node.js, and npm version?

  • webpack v5.5.1
  • node v12.9.1
  • yarn 1.22.10
  • simple-signal-client 3.0.0

What happened?
When receiving peer data, error is thrown:

_stream_readable.js:905 Uncaught (in promise) ReferenceError: process is not defined
    at _stream_readable.js:905
    at f.E.resume (_stream_readable.js:895)
    at f.E.on (_stream_readable.js:813)
    at App.js:25
    at c (runtime.js:63)
    at Generator._invoke (runtime.js:293)
    at Generator.next (runtime.js:118)
    at t (asyncToGenerator.js:3)
    at s (asyncToGenerator.js:25)

What did you expect to happen?
In frontend (using signaling module simple-signal-client) the peer should receive data messages with no errors:

peer.on('data', (data) => {
  // ...
})

Are you willing to submit a pull request to fix this bug?

Not a pull request, but a solution. The problem is in webpack 5 now you need to add process explicitly.

To do so

  1. Add module process to the project (Example: yarn add --dev process)
  2. Add it as plugin in webpack config
const webpack = require('webpack')
// ...
module.exports = {
  // ...
  plugins: [
      // ...
      new webpack.ProvidePlugin({
        process: 'process/browser',
      }) 
  ]
}

This is not compatible with msgpack-javascript (for some reason).
If you want a more compatible solution use https://www.npmjs.com/package/node-polyfill-webpack-plugin .
I have no idea how or why but it does seem to work.