{"action":"created","issue":{"url":"https://api.github.com/repos/npm/npm/issues/7276","labels_url":"https://api.github.com/repos/npm/npm/issues/7276/labels{/name}","comments_url":"https://api.github.com/repos/npm/npm/issues/7276/comments","events_url":"https://api.github.com/repos/npm/npm/issues/7276/events","html_url":"https://github.com/npm/npm/issues/7276","id":56505972,"number":7276,"title":"The way dependencies of dependencies are dealt with is kinda broken","user":{"login":"callumacrae","id":472830,"avatar_url":"https://avatars.githubusercontent.com/u/472830?v=3","gravatar_id":"","url":"https://api.github.com/users/callumacrae","html_url":"https://github.com/callumacrae","followers_url":"https://api.github.com/users/callumacrae/followers","following_url":"https://api.github.com/users/callumacrae/following{/other_user}","gists_url":"https://api.github.com/users/callumacrae/gists{/gist_id}","starred_url":"https://api.github.com/users/callumacrae/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/callumacrae/subscriptions","organizations_url":"https://api.github.com/users/callumacrae/orgs","repos_url":"https://api.github.com/users/callumacrae/repos","events_url":"https://api.github.com/users/callumacrae/events{/privacy}","received_events_url":"https://api.github.com/users/callumacrae/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/npm/npm/labels/feature-request","name":"feature-request","color":"ACE1AF"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/npm/npm/milestones/4","html_url":"https://github.com/npm/npm/milestones/multi-stage%20install","labels_url":"https://api.github.com/repos/npm/npm/milestones/4/labels","id":730261,"number":4,"title":"multi-stage install","description":null,"creator":{"login":"othiym23","id":418097,"avatar_url":"https://avatars.githubusercontent.com/u/418097?v=3","gravatar_id":"","url":"https://api.github.com/users/othiym23","html_url":"https://github.com/othiym23","followers_url":"https://api.github.com/users/othiym23/followers","following_url":"https://api.github.com/users/othiym23/following{/other_user}","gists_url":"https://api.github.com/users/othiym23/gists{/gist_id}","starred_url":"https://api.github.com/users/othiym23/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/othiym23/subscriptions","organizations_url":"https://api.github.com/users/othiym23/orgs","repos_url":"https://api.github.com/users/othiym23/repos","events_url":"https://api.github.com/users/othiym23/events{/privacy}","received_events_url":"https://api.github.com/users/othiym23/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":75,"state":"open","created_at":"2014-07-23T22:21:24Z","updated_at":"2015-05-14T18:56:02Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2015-02-04T09:58:53Z","updated_at":"2015-05-14T18:56:02Z","closed_at":"2015-05-14T18:56:02Z","body":"I've had two issues with dependencies of dependencies in the last week.\r\n\r\nWhen you have two dependencies, \"foo\" and \"bar\", and \"bar\" is also a dependency of \"foo\", \"bar\" won't be installed twice.\r\n\r\nThis is what I would expect:\r\n\r\n```\r\n❯ tree\r\n.\r\n└── node_modules\r\n    ├── bar\r\n    └── foo\r\n        └── node_modules\r\n            └── bar\r\n```\r\n\r\nThis is what actually happens:\r\n\r\n```\r\n❯ tree\r\n.\r\n└── node_modules\r\n    ├── bar\r\n    └── foo\r\n```\r\n\r\nI can completely understand why this happens! It means the module is only downloaded once, instead of being downloaded multiple times, and it still works fine because of how `require` works.\r\n\r\n---\r\n\r\nHowever, it has side effects:\r\n\r\nIf I were to uninstall \"bar\" using npm because, say, I don't need it anymore, the \"foo\" module would start erroring because it can't find \"bar\". This one is pretty easy to work around: just figure out which dependencies rely on \"bar\", and copy \"bar\" into those dependencies (or reinstall them).\r\n\r\nThe other side effect is less common, and trickier to deal with. When there's a module designed to load other modules, it might expect to be requiring them in a different node_modules directory to the one it is actually in.\r\n\r\n```\r\n.\r\n├── index.js\r\n└── node_modules\r\n    ├── include\r\n    └── foo\r\n        ├── foo.js\r\n        └── node_modules\r\n            └── bar\r\n```\r\n\r\ninclude/index.js:\r\n\r\n```js\r\nmodule.exports = function (name) {\r\n    return require(name);\r\n};\r\n```\r\n\r\nIf we call `include()` from index.js, it works as expected. However, if we call `include()` from node_modules/foo/foo.js, we are expecting to get dependencies from node_modules/foo/node_modules: however, it will only get dependencies from node_modules.\r\n\r\nIt's a pretty obscure bug, but it has cropped up in the wild: jackfranklin/gulp-load-plugins#56\r\n\r\n----\r\n\r\nI have no idea what can be done about this—I completely understand why you don't want to download the same dependency multiple times when it doesn't really need to be, but it does have some weird side effects."},"comment":{"url":"https://api.github.com/repos/npm/npm/issues/comments/102135026","html_url":"https://github.com/npm/npm/issues/7276#issuecomment-102135026","issue_url":"https://api.github.com/repos/npm/npm/issues/7276","id":102135026,"user":{"login":"iarna","id":983798,"avatar_url":"https://avatars.githubusercontent.com/u/983798?v=3","gravatar_id":"","url":"https://api.github.com/users/iarna","html_url":"https://github.com/iarna","followers_url":"https://api.github.com/users/iarna/followers","following_url":"https://api.github.com/users/iarna/following{/other_user}","gists_url":"https://api.github.com/users/iarna/gists{/gist_id}","starred_url":"https://api.github.com/users/iarna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iarna/subscriptions","organizations_url":"https://api.github.com/users/iarna/orgs","repos_url":"https://api.github.com/users/iarna/repos","events_url":"https://api.github.com/users/iarna/events{/privacy}","received_events_url":"https://api.github.com/users/iarna/received_events","type":"User","site_admin":false},"created_at":"2015-05-14T18:56:02Z","updated_at":"2015-05-14T18:56:02Z","body":"I'm closing this as its actually a complete feature in `multi-stage`."}}