wufe / react-particles-js

Particles.js for React
https://rpj.bembi.dev/
MIT License
1.15k stars 106 forks source link

Uncaught TypeError: Super expression must either be null or a function #105

Closed arianitu closed 4 years ago

arianitu commented 4 years ago

When I use webpack and do a production build, it breaks in production. Stack points to this library and after I no longer include react-particles-js I do not get this error anymore.

Specifically breaks on }(f.Component);

Does anyone use this with webpack or in production?

            Object.defineProperty(t, "__esModule", {
                value: !0
            });
            var l = s(n(14))
              , f = n(14)
              , d = n(2)
              , p = u(n(37))
              , h = function(e) {
                function t(e) {
                    var n;
                    return function(e, t) {
                        if (!(e instanceof t))
                            throw new TypeError("Cannot call a class as a function")
                    }(this, t),
                    (n = function(e, t) {
                        return !t || "object" !== r(t) && "function" != typeof t ? a(e) : t
                    }(this, c(t).call(this, e))).state = {
                        canvas: void 0,
                        library: void 0
                    },
                    n.loadCanvas = n.loadCanvas.bind(a(n)),
                    n
                }
                var n, s;
                return function(e, t) {
                    throw new TypeError("Super expression must either be null or a function")
                }(),
                n = t,
                (s = [{
                    key: "buildParticlesLibrary",
                    value: function(e) {
                        try {
                            if (void 0 === window)
                                return null
                        } catch (e) {
                            return null
                        }
                        return new d.ParticlesLibrary(e)
                    }
                }, {
                    key: "refresh",
                    value: function(e) {
                        var t = this
                          , n = this.state.canvas;
                        n && (this.destroy(),
                        this.setState({
                            library: this.buildParticlesLibrary(e.params)
                        }, function() {
                            t.loadCanvas(n)
                        }))
                    }
                }, {
                    key: "destroy",
                    value: function() {
                        this.state.library && this.state.library.destroy()
                    }
                }, {
                    key: "loadCanvas",
                    value: function(e) {
                        var t = this;
                        e && this.setState({
                            canvas: e
                        }, function() {
                            var n = t.state.library;
                            n && (n.loadCanvas(e),
                            n.start())
                        })
                    }
                }, {
                    key: "shouldComponentUpdate",
                    value: function(e) {
                        return !p.default(e, this.props)
                    }
                }, {
                    key: "componentDidUpdate",
                    value: function() {
                        this.refresh(this.props)
                    }
                }, {
                    key: "forceUpdate",
                    value: function() {
                        this.refresh(this.props),
                        i(c(t.prototype), "forceUpdate", this).call(this)
                    }
                }, {
                    key: "componentDidMount",
                    value: function() {
                        this.setState({
                            library: this.buildParticlesLibrary(this.props.params)
                        })
                    }
                }, {
                    key: "componentWillUnmount",
                    value: function() {
                        this.destroy(),
                        this.setState({
                            library: void 0
                        })
                    }
                }, {
                    key: "render",
                    value: function() {
                        var e = this.props
                          , t = e.width
                          , n = e.height
                          , r = e.className
                          , o = e.canvasClassName;
                        return l.createElement("div", {
                            className: r
                        }, l.createElement("canvas", {
                            ref: this.loadCanvas,
                            className: o,
                            style: Object.assign(Object.assign({}, this.props.style), {
                                width: t,
                                height: n
                            })
                        }))
                    }
                }]) && o(n.prototype, s),
                t
            }(f.Component);
arianitu commented 4 years ago

This was a bug from terser-webpack-plugin version 1.2.3. See https://github.com/terser/terser/issues/308

We fixed it by running npm install terser-webpack-plugin@latest