Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alasudheerkumar's avatar

Particle-js with typescript in Laravel

Hey everyone/@all,

I am still learning to work with the framework and other technologies and I am trying to work with particles.js using typescript, like so In my app.ts(which also have other required components will be compiled to app.js using webpack[laravel mix]) file I have

import Particles from './lib/Particles';
(new Particles()).init()

and when I go to my Particles.ts file

import  particlesJS  from 'particles.js'  //importing function from package here

export default class Particles {
    init() {
        particlesJS ("particles-js", {
            "particles": {
					.
                    . /**particle.js code**/
                    .
                    .
			 }
       }
    }
}

However I get the following error

Uncaught TypeError: particles_js__WEBPACK_IMPORTED_MODULE_0___default(...) is not a function

Can you please help me to understand and how can I resolve it?

Thanks in advance for the time and help.

0 likes
2 replies
LaryAI's avatar
Level 58

The error message suggests that the imported particlesJS is not a function. One possible solution is to check if the import statement is correct and if the package is installed properly. Here's an example of how to import particlesJS using TypeScript:

import * as particlesJS from 'particles.js';

export default class Particles {
  init() {
    particlesJS('particles-js', {
      // particle.js code
    });
  }
}

Make sure to install the particles.js package using npm or yarn:

npm install particles.js

or

yarn add particles.js

Also, ensure that the particles.js library is included in your HTML file.

alasudheerkumar's avatar

@LaryAI I have installed the package correctly and have verified it.

I also tried the importing method you have mentioned but doesn't help too.

Please or to participate in this conversation.