Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a dependency of another dependency?

Tags:

node.js

npm

I have a package (babel-preset-es2015-webpack) with dependency babel-preset-es2015. babel-preset-es2015 have dependency babel-plugin-transform-es2015-modules-commonjs.

How do I require babel-plugin-transform-es2015-modules-commonjs in a way to make sure that it is the same package that my babel-present-es2015 dependency is using?

Simply doing:

require('babel-plugin-transform-es2015-modules-commonjs');

Will work in NPM3 setup (assuming there are no other dependencies that require a different version of babel-plugin-transform-es2015-modules-commonjs), but will not work in NPM2.

like image 334
Gajus Avatar asked Jan 07 '16 12:01

Gajus


People also ask

How do you find transitive dependencies?

You can get this information in the Maven Tool Window. First go to View → Tool Windows → Maven, to make sure that the Maven window is visible. The top-level elements in the tree are your direct dependencies, and the child elements are the transitive dependencies.

Where does Maven get dependencies from?

Maven's local repository is a directory on the local machine that stores all the project artifacts. When we execute a Maven build, Maven automatically downloads all the dependency jars into the local repository. Usually, this directory is named .

How do I override nested dependency?

Remove the nested dependency under the 'requires' section in package-lock. json. Add the updated dependency under DevDependencies in package. json, so that modules that require it will still be able to access it.

What is dependencyManagement in Maven?

What Is Maven Dependency Management? Dependency management in Maven allows teams to manage dependencies for multi-module projects and applications. These can consist of hundreds or even thousands of modules. Using Maven can help teams define, create, and maintain reproducible builds.


1 Answers

If you do not want to use shrinkwrap as noted by @Nocturno, you can also simply require the specific path to the dependency:

require('<path-to-node_modules>/babel-preset-es2015-webpack/node_modules/babel-plugin-transform-es2015-modules-commonjs');

Never used the plugins myself, but something like the above should work.

Another option is to lock down babel-preset-es2015-webpack to a specific version, then determine what version of babel-plugin-transform-es2015-modules-commonjs is listed in it's package.json and add it to your package.json. Then you can use the require('babel-plugin-transform-es2015-modules-commonjs'); method in NPM2 and NPM3.

like image 113
wjohnsto Avatar answered Oct 14 '22 22:10

wjohnsto