particles.js and window is not defined

前端 未结 1 520
[愿得一人]
[愿得一人] 2021-01-28 18:12

When I start my app using node app.js then then I get the following error:

/home/ubuntu/workspace/nodeapp/node_modules/particles.js/particles.js:142         


        
相关标签:
1条回答
  • 2021-01-28 19:00

    This is because window is a browser object, and it looks like you're trying to load particle.js on the server side, in node.

    Try moving your particlesJS.load call into the browser.

    From their npm page:

    Initialize the plugin on the window.onload event.

    window.onload = function() {
      Particles.init({
        selector: '.background'
      });
    };
    
    0 讨论(0)
提交回复
热议问题