Roots Discourse

Particles.js error 'particlesJS' is not defined

I’ve been trying to integrate particles.js into my theme., however, I keep running into the error "error ‘particlesJS’ is not defined"

  • particles.js successfully included with yarn add particles.js
  • import ‘particles.js’ in main.js

The error actors when I go into my home.js file, and right under the line export default { init() { I start to insert my app.js file content, and the error is output.

I can’t seem to find a successful way to include particles into sage, I’m able to make it work on a any other Wordpress theme I create.

Not sure but maybe this could help you, try it.

import 'particles.js/particles';
const particlesJS = window.particlesJS;
particlesJS.load('particles-js', 'particles.json', null);

This compiles, however now I receive a number of other errors

  • Error pJS - XMLHttpRequest status: 404
  • particles.js:1535 Error pJS - File config not found

I’m not familiar w/ the library, but the above looks like it’s failing to load your configuration file.

particlesJS.load('particles-js', 'particles.json', null);

If you’re using that code, it’s looking for a file called particles.json. Does that file exist, and in the location where the script is looking for it?

It’s been a year since I looked at Particles.js within sage. (and i wasn’t too great at using sage 9 / local Wordpress at that point). If i Remember correct, Chrome doesn’t allow Ajax calls to local Json files? so it might not work until you load it up.