Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM: How do I find the parent of a child package?

Tags:

node.js

npm

I have a bunch of older packages (Maintaining an Angularjs (1.0) stack) and when I am installing I get warnings about outdated versions of packages:

npm WARN deprecated [email protected]: ...psst! Your project can stop working at any moment because its dependencies can change. Prevent this by migrating to Yarn: https://bower.io/
blog/2017/how-to-migrate-away-from-bower/
npm WARN deprecated [email protected]: πŸ™Œ  Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update! 
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN deprecated [email protected]: Use uuid module instead
npm WARN deprecated [email protected]: this package has been reintegrated into npm and is now out of date with respect to npm

How do I find out which package is pulling these in?

npm outdated returns nothing. npm prune prunes nothing.

package.json

{                                                           
  "devDependencies": {                                                          
    "babel-preset-env": "^1.6.1",                                                          
    "browser-sync-webpack-plugin": "^2.2.2",                                                          
    "copy-webpack-plugin": "^4.5.1",                                                          
    "html-webpack-plugin": "^3.1.0",                                                          
    "css-loader": "^0.28.11",                                                          
    "file-loader": "^1.1.11",                                                          
    "pug-html-loader": "^1.1.5",                                                          
    "pug-loader": "^2.3.0",                                                          
    "graceful-fs": "^4.1.11",                                                          
    "minimatch": "^3.0.4",                                                          
    "node-sass": "^4.8.3",                                                          
    "sass-loader": "^6.0.7",                                                          
    "style-loader": "^0.20.3",                                                          
    "uglifyjs-webpack-plugin": "^1.2.4",                                                          
    "webpack": "^4.3.0",                                                          
    "webpack-cli": "^2.0.13",                                                          
    "webpack-merge": "^4.1.2"                                                          
  },                                                    
  "dependencies": {                                                          
    "@uirouter/angularjs": "latest",
    "ajv": "^6.3.0",                                                         
    "angular": "^1.6.9",                                                          
    "angular-translate": "^2.17.0",                                                          
    "babel-core": "^6.26.0",                                                          
    "babel-loader": "^7.1.4",                                                          
    "babel-plugin-transform-runtime": "^6.23.0",                                                          
    "babel-register": "^6.26.0",                                                          
    "brfs": "^1.5.0",                                                          
    "browser-sync": "^2.23.6",                                                          
    "debowerify": "^1.4.1",                                                          
    "isparta": "^4.0.0",                                                          
    "jshint": "^2.9.5",                                                          
    "jshint-stylish": "^2.2.0",                                                          
    "postcss-loader": "^2.1.3",                                                          
    "pretty-hrtime": "^1.0.2",                                                          
    "pug": "^2.0.3",                                                          
    "tiny-lr": "^1.1.1"                                                          
  }                                                         
}  
like image 215
Andre Lewis Avatar asked Mar 27 '18 21:03

Andre Lewis


People also ask

How do I find the dependency tree in npm?

Use the npm list to show the installed packages in the current project as a dependency tree. Use npm list --depth=n to show the dependency tree with a specified depth.

What is module parent?

The "parent" is the module that caused the script to be interpreted (and cached), if any: // $ node foo.js console. log(module.

How do I update my childs npm?

Delete node_modules folder and package.json files. You then run npm install and the packages should be updated.

What does npm ls command do?

Description. This command will print to stdout all the versions of packages that are installed, as well as their dependencies, in a tree-structure. It will print out extraneous, missing, and invalid packages.


2 Answers

You can do npm ls --all. It will give you a tree structure showing how dependencies fits together. Example below:

lms@nuc ~/src/ralphtheninja/slump (master)
$ npm ls --all                            
[email protected] /home/lms/src/ralphtheninja/slump
β”œβ”€β”¬ [email protected]                 
β”‚ └─┬ [email protected]                   
β”‚   └── [email protected] deduped       
β”œβ”€β”€ [email protected]             
β”œβ”€β”¬ [email protected]              
β”‚ β”œβ”€β”€ [email protected]                  
β”‚ β”œβ”€β”€ [email protected]                    
β”‚ β”œβ”€β”€ [email protected]                      
β”‚ β”œβ”€β”€ [email protected]                      
β”‚ β”œβ”€β”¬ [email protected]
β”‚ β”‚ β”œβ”€β”€ [email protected] deduped
β”‚ β”‚ └─┬ [email protected]
β”‚ β”‚   β”œβ”€β”€ [email protected] deduped
β”‚ β”‚   β”œβ”€β”€ [email protected] deduped
β”‚ β”‚   β”œβ”€β”€ [email protected]
β”‚ β”‚   └── [email protected]
β”‚ β”œβ”€β”¬ [email protected]
β”‚ β”‚ β”œβ”€β”€ [email protected]
β”‚ β”‚ β”œβ”€β”€ [email protected] deduped
β”‚ β”‚ β”œβ”€β”€ [email protected] deduped
β”‚ β”‚ β”œβ”€β”€ [email protected]
β”‚ β”‚ β”œβ”€β”€ [email protected] deduped
β”‚ β”‚ └── [email protected] deduped
β”‚ └─┬ [email protected]
β”‚   β”œβ”€β”€ [email protected] deduped
β”‚   └─┬ [email protected]
β”‚     └── [email protected]
β”œβ”€β”¬ [email protected]
β”‚ β”œβ”€β”€ [email protected]
β”‚ β”œβ”€β”€ [email protected]
β”‚ β”œβ”€β”€ [email protected]
β”‚ └── [email protected]
β”œβ”€β”€ [email protected]

If you're wondering about a specific package, you can do npm ls <package>, which will show that sub tree.

You can also do npm ls --json to get it in json formatted output. Useful if you want to analyze it programmatically.

EDIT: Original post suggested using npm ls but newer versions of npm ls only displays a flat list.

like image 95
ralphtheninja Avatar answered Sep 24 '22 08:09

ralphtheninja


I recommend you upgrade your dependencies by using npm-check-updates.
You can install with: npm install -g npm-check-updates
Then by runnig ncu gives you a report of outdated packages or ncu -u updates the package.json.
More info about ncu here.

Otherwise, package-lock.json can give you information about dependencies of dependencies. Alternatively, npm ls can give you a report.

like image 23
Csaba Avatar answered Sep 20 '22 08:09

Csaba