*ReferenceError*: process is not defined from brow...
# javascript
r
ReferenceError: process is not defined from browser library
Copy code
index.mjs:2615 Uncaught ReferenceError: process is not defined
    at ../../node_modules/@whereby.com/media/dist/index.mjs (index.mjs:2615:1)
    at __webpack_require__ (bootstrap:24:1)
I'm importing an ES module, whereby. It's intended to run in the browser, and yet it references process. The line that's blowing up:
Copy code
const server = rtcStatsConnection(process.env.RTCSTATS_URL || "<wss://rtcstats.srv.whereby.com>");
I tried adding https://www.npmjs.com/package/process and:
Copy code
external fun require(mod: String): dynamic

@OptIn(ExperimentalJsExport::class)
@JsExport
fun main() {
    require("process")
}
...but this doesn't fix it. (I realize that it only adds process.browser, but I still get "process is undefined")
t
Probably you need
DefinePlugin
for webpack
Example you can find in
kfc-plugins
r
Nice, thanks! I made a webpack.config.js with:
Copy code
const webpack = require('webpack');

config.plugins.push(
    new webpack.DefinePlugin({
        'process': JSON.stringify({
            env: {
                RTCSTATS_URL: '<wss://rtcstats.srv.whereby.com>'
            }
        }),
        'process.env': JSON.stringify({
            RTCSTATS_URL: '<wss://rtcstats.srv.whereby.com>'
        }),
        'process.env.RTCSTATS_URL': JSON.stringify('<wss://rtcstats.srv.whereby.com>')
    })
);
t
3rd replace - is what you need
r
what do you mean?
t
Copy code
'process.env.RTCSTATS_URL': JSON.stringify('<wss://rtcstats.srv.whereby.com>')
    })
this replacement - probably single required
r
Ah I see - yeah, thanks