javascript - How did the unpublishing of npm left-pad break code? - Stack Overflow

I've been reading up on the npm left-pad fiasco, but I'm somewhat confused by how it happened

I've been reading up on the npm left-pad fiasco, but I'm somewhat confused by how it happened. I think I have a misunderstanding of how npm actually works. If the developer of left-pad unpublished the package, I assume npm install left-pad wouldn't work anymore. However, for users who had already installed it, won't left-pad still be in the node_modules folder? Wouldn't the developers of say, Babel, have to remove and reinstall left-pad for npm to realize that the package has disappeared? I am clearly missing something, but I'm not sure what.

I've been reading up on the npm left-pad fiasco, but I'm somewhat confused by how it happened. I think I have a misunderstanding of how npm actually works. If the developer of left-pad unpublished the package, I assume npm install left-pad wouldn't work anymore. However, for users who had already installed it, won't left-pad still be in the node_modules folder? Wouldn't the developers of say, Babel, have to remove and reinstall left-pad for npm to realize that the package has disappeared? I am clearly missing something, but I'm not sure what.

Share Improve this question asked Aug 30, 2016 at 20:46 Timothy DengTimothy Deng 4941 gold badge6 silver badges17 bronze badges 1
  • 5 You're not misunderstanding NPM, you're misinterpreting the clickbait titles that were around at the time. It means it would break if anyone tried npm installing from package.json referncing the left-pad, not literally run-time. I've even seen a title along the lines of "How one man almost broke the internet". Sigh. – Lazar Ljubenović Commented Aug 30, 2016 at 20:49
Add a ment  | 

2 Answers 2

Reset to default 10

When I run npm install babel, left-pad is not bundled in babel but rather is expressed as dependency in it's package.json file. So npm then has to go find left-pad and download it as well. So if you were installing left-pad or anything using left-pad for the first time, you wouldn't be able to. While this means you're safe if it already exists in your local directory, the project would fail to build properly as soon as it is built somewhere else. For example, a CI server that does a clean build from scratch for each new changeset would fail to build any project that relies on left-pad. Or if you were checking out a project for the first time, or deploying it to a new server, you wouldn't be able to build.

This is simple to fix if you were relying on left-pad directly. Just write a replacement and update your code to use the replacement. But when it's required deep in your dependency tree, say by Babel, it's unlikely you can refactor Babel or other modules on your own to use a left-pad replacement. You'd have to wait for all of the various node module developers to update their modules with something else and republish.

It's not as apocalyptic as news articles made it sounds, but it is a huge inconvenience and throws a wrench in many systems outside of developer workspaces where left-pad was already cached.

As @Lazar said, you understood correctly.

The problem e in that, if Babel is relying on left-pad, and am trying to install Babel, it will fail.

Well, I could always rewrite it myself as a workaround.

But if it is a module used by a module used by a module used by... used by Babel, or more module, you face a real nightmare, because Babel can't do anything, nor can you, and you are forced to wait that every single module develloper relying on left-pad update their code.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744084895a4555986.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信