Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Can't resolve 'tsparticles' in '/home/manujtiwari/Desktop/portfolio-react/node_modules/react-particles-js/cjs'

Tags:

reactjs

I am unable to use react particles in my project. Following the documentation, i installed react-particles, and when it did not work, i installed react-tsparticles but still it gives me same error: Module not found: Can't resolve 'tsparticles' Please Help me in this. Below is my dependency file.

{
  "name": "portfolio-react",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@fortawesome/free-solid-svg-icons": "^5.15.3",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "bootstrap": "^5.0.2",
    "react": "^17.0.2",
    "react-bootstrap": "^1.6.1",
    "react-dom": "^17.0.2",
    "react-particles-js": "^3.5.3",
    "react-scripts": "4.0.3",
    "react-tsparticles": "^1.30.4",
    "react-typed": "^1.2.0",
    "web-vitals": "^1.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "tslint": "^5.0.0"
  }
}
like image 590
Manuj Tiwari Avatar asked Jul 08 '21 10:07

Manuj Tiwari


4 Answers

When you install the npm i react-particles-js in your project. In the initial doc the develper mentioned the react-particles-js is dependant on "tsparticles" so you just install "npm i tsparticles".

npm i tsparticles

Nothing else and restart your server .I think this time its working fine. Here is my Particle component.

import React from 'react'
import Particles from 'react-particles-js'

function Particless  (){
    return (
      <Particles
      params={{
        particles: {
          number: {
            value: 200,
            density: {
              enable: true,
              value_area: 1000,
            }
          },
        },
      }}
    />
    )
}

export default Particless
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
like image 149
Narendra Maurya Avatar answered Oct 21 '22 13:10

Narendra Maurya


try installing ts particles npm package as this should fix the issue

like image 37
Rishi Bhachu Avatar answered Oct 21 '22 13:10

Rishi Bhachu


Uninstall "react-particles-js", because it's deprecated. Install "react-particles" instead.

npm install react-particles

In your Component:

import Particles from "react-particles";
like image 35
Diyan Kalaydzhiev Avatar answered Oct 21 '22 13:10

Diyan Kalaydzhiev


here is what I did.

removed the node modules > removed the packagelock.json > npm i tsparticles

then it worked for me.

like image 42
Manzim Avatar answered Oct 21 '22 13:10

Manzim