Last Updated: February 25, 2016
· douglasduteil

One does not simply use peerDependencies.

One does not simply use peerDependencies.

peerDependencies done right lightly.


I had a really bad time with peerDependencies. So I started looking around to find how I can actually have the same behavior without the peerDependencies frustration...

I found a fairly simple way to achieve it using the substack/node-resolve. The trick is that with it we can resolve from the current working directory :

Example with a 6to5 plugin

var resolve = require('resolve');

var to5;
try {
  to5 = require(resolve.sync('6to5', { basedir: process.cwd() }));
} catch (_) {
  console.warn('Processing using inner 6to5. version : ' + to5.version);
  to5 = require('6to5');

// Do stuff with 6to5 here...

This way :

  • you can to have 6to5 as a dependency in your project.
  • you don't need to have 6to5 as a dependency or devDependency in your plugin.

See my douglasduteil/isparta Karma plugin to generate code coverage for ES6 using the 6to5.

Going forward

It might be a good idea to add some more stuff to that like semver checking but this will be for another post...