A bad npm pkg

Sometimes you encounter a bad npm package. It’s not bad in terms of functionality - otherwise you might not have to use it. It’s bad in the sense that its setup doesn’t align with npm pkg requirements.

Was using social-share.js to create social share buttons. It works fine using script tags. But it doesn’t when imported/required from node_modules.

In a fine afternoon, I had fun debugging this one. Had the chance to refresh my memories on require.resolve, node --inspect, webpack loader and bunch of other stuff. Turned out:

In social-share.js’s package.json, it has

main: dist/js/share.min.js

That files doesn’t exist. It should be

main: dist/js/social-share.min.js

The difference was too small to be spotted from error messages. But how could this bug be written in the first place? It’s because they don’t use it as a npm package.

Written on October 24, 2018