Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'prop-types' should be listed in the project's dependencies, not devDependencies

I ran npm install prop-types --save-dev and started getting this error

'prop-types' should be listed in the project's dependencies, not devDependencies import/no-extraneous-dependencies

Later I uninstalled the dependency by running npm uninstall prop-types --save-dev and installed again by running npm install prop-types --save

Still the error doesn't go

'prop-types' should be listed in the project's dependencies. Run 'npm i -S prop-types' to add it import/no-extraneous-dependencies

like image 351
Rahul Yadav Avatar asked Jan 24 '21 00:01

Rahul Yadav


People also ask

Should prop types be Dev dependency?

javascript - 'prop-types' should be listed in the project's dependencies, not devDependencies - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

Which packages should be in devDependencies?

devDependencies : Packages that are only needed for local development and testing. In short, you should save a module as a devDependency when it's only used for development and testing; everything else should be a dependency .

What's the difference between dependencies and devDependencies?

A dependency is a library that a project needs to function effectively. DevDependencies are the packages a developer needs during development.

Which modules are considered as devDependencies in react project?

For example, modules that are imported by your front-end application and the frameworks themselves (such as React, Angular, Vue, Svelte, etc), would all go in the package. json file as dependencies. The bundlers, pre-processors, transpilers, etc, instead, would go in as devDependencies.


2 Answers

Your package.json probably currently looks something like

{
  "name": "your-website",
  ...
  "dependencies": {
    "react": "^16.10.2",
    "react-dom": "^16.10.2",
    "webpack": "^4.44.1",
    ...

  },
  "devDependencies": {
    "prop-types": "^15.7.2",
    "@types/node": "^14.0.18",
    ...
  },
}

Make it look like

{
  "name": "your-website",
  ...
  "dependencies": {
    "react": "^16.10.2",
    "react-dom": "^16.10.2",
    "webpack": "^4.44.1",
    "prop-types": "^15.7.2",
    ...

  },
  "devDependencies": {
    "@types/node": "^14.0.18",
    ...
  },
}

by moving prop-types from devDependencies to dependencies

After this, run npm install or yarn install if you are using yarn


Your devDependencies are the ones that are used while building your project. They are not present in the production of your project. When someone opens a website in a browser the code for the devDependencies is not in it


When you install a package

  • using npm install will put the package into your package.json as a dependency
  • using npm install --save-dev will put the package in your package.json as a devDependency
like image 89
Sam Avatar answered Oct 16 '22 19:10

Sam


You should execute this command: rm -rfd ./node_modules to delete node_modules directory and then change your package.json manually like this:

  "dependencies": {
    ...
    "prop-types": <YOUR_VERSION>,
  },
  "devDependencies": {
    ...
  },

and finally, run npm i or yarn if you're using yarn.

like image 36
amir salehi Avatar answered Oct 16 '22 20:10

amir salehi