Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create npm/yarn dependency tree from just package.json; without creating node_modules folder

I inherited an application which works fine in node8, but npm install fails in node10, giving an error about fibers package being built using node-gyp

fibers is not a direct dependency of the app, so I want to know which dependency is bringing in fibers as it's dependency.

Unfortunately, npm ls, yarn why only works when node_modules is generated completely through npm install or yarn install. I did research online but couldn't find a static dependency tree generator just from package.json.

Even though I could just use node8 and run npm install followed by npm ls to figure out whose bringing in fibers; I believe there should be an easier static analysis of package.json.

Is there no way to statically analyze a package.json and create a dependency graph for it in npm/nodejs ?

I come from java and we had maven which can just analyze a file named pom.xml to create a nice graph about whats coming from where.

like image 768
coding_idiot Avatar asked Jun 02 '26 12:06

coding_idiot


1 Answers

  1. Execute npm install in the directory and let it fail.
  2. It'll output something like A log of this can be found at <location>
  3. Open the log file and search for the text saveTree.
  4. Notice a hierarchy of resolved packages
  5. Here you can find the module you're looking for and whose bringing it in.
like image 148
coding_idiot Avatar answered Jun 04 '26 04:06

coding_idiot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!