{"action":"created","issue":{"url":"https://api.github.com/repos/google/closure-compiler/issues/954","labels_url":"https://api.github.com/repos/google/closure-compiler/issues/954/labels{/name}","comments_url":"https://api.github.com/repos/google/closure-compiler/issues/954/comments","events_url":"https://api.github.com/repos/google/closure-compiler/issues/954/events","html_url":"https://github.com/google/closure-compiler/issues/954","id":77594014,"number":954,"title":"Cannot process node module dependencies","user":{"login":"Kegsay","id":7190048,"avatar_url":"https://avatars.githubusercontent.com/u/7190048?v=3","gravatar_id":"","url":"https://api.github.com/users/Kegsay","html_url":"https://github.com/Kegsay","followers_url":"https://api.github.com/users/Kegsay/followers","following_url":"https://api.github.com/users/Kegsay/following{/other_user}","gists_url":"https://api.github.com/users/Kegsay/gists{/gist_id}","starred_url":"https://api.github.com/users/Kegsay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kegsay/subscriptions","organizations_url":"https://api.github.com/users/Kegsay/orgs","repos_url":"https://api.github.com/users/Kegsay/repos","events_url":"https://api.github.com/users/Kegsay/events{/privacy}","received_events_url":"https://api.github.com/users/Kegsay/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-05-18T10:09:09Z","updated_at":"2015-05-20T08:56:59Z","closed_at":"2015-05-18T15:18:05Z","body":"I want to compile this very simple piece of code:\r\n\r\n```javascript\r\n// test.js\r\nvar crypto = require(\"crypto\");\r\nconsole.log(crypto.createHash(\"md5\").update(\"foo\").digest(\"hex\"));\r\n```\r\nI know the compiler needs to know where the ``crypto`` library is, so I'm passing it in via ``--externs`` (I do *not* want it to be compiled along with my code, I just want it bluntly passed through).\r\n\r\nHowever, I cannot get this to compile at all. I'm compiling it with:\r\n```\r\n$ java -jar compiler.jar --js=\"test.js\" --process_common_js_modules --common_js_entry_module \"test.js\" --externs closure-compiler/contrib/nodejs/crypto.js\r\n\r\nERROR - required entry point \"module$crypto\" never provided\r\n\r\n1 error(s), 0 warning(s)\r\n```\r\n\r\nwhere ``closure-compiler/contrib/nodejs/crypto.js`` is the file in this git repo. I've also tried using ``globals.js`` to no avail. What am I doing wrong? Looking at the source, it's producing this error because ``module$crypto`` is not contained in ``modulesByProvide`` in ``src/com/google/javascript/jscomp/Compiler.java:1534``, which seems to just be looping over the files I give it in ``--js`` and not the externs files.\r\n\r\nVersion:\r\n```\r\nClosure Compiler (http://github.com/google/closure-compiler)\r\nVersion: v20150505\r\nBuilt on: 2015/05/06 13:09\r\n```"},"comment":{"url":"https://api.github.com/repos/google/closure-compiler/issues/comments/103815254","html_url":"https://github.com/google/closure-compiler/issues/954#issuecomment-103815254","issue_url":"https://api.github.com/repos/google/closure-compiler/issues/954","id":103815254,"user":{"login":"Kegsay","id":7190048,"avatar_url":"https://avatars.githubusercontent.com/u/7190048?v=3","gravatar_id":"","url":"https://api.github.com/users/Kegsay","html_url":"https://github.com/Kegsay","followers_url":"https://api.github.com/users/Kegsay/followers","following_url":"https://api.github.com/users/Kegsay/following{/other_user}","gists_url":"https://api.github.com/users/Kegsay/gists{/gist_id}","starred_url":"https://api.github.com/users/Kegsay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kegsay/subscriptions","organizations_url":"https://api.github.com/users/Kegsay/orgs","repos_url":"https://api.github.com/users/Kegsay/repos","events_url":"https://api.github.com/users/Kegsay/events{/privacy}","received_events_url":"https://api.github.com/users/Kegsay/received_events","type":"User","site_admin":false},"created_at":"2015-05-20T08:56:59Z","updated_at":"2015-05-20T08:56:59Z","body":"Aliasing `require` does indeed work, which is a great start: thank you!\r\n\r\nSo overall, there isn't any way to specify where closure-compiler should look to resolve references like this? E.g. A compiler option to say \"If you see a `require` call, look in `some/dir/here`\"? Clearly the `require` call is *already* doing something like this since it can resolve paths correctly. It seems surprising that closure-compiler has this half-support for `require` calls (in that it resolves files/paths correctly, just not anything native like `crypto` or anything in `node_modules`). \r\n\r\nThe benefit to doing this would be that it would allow type checking on Node.js projects without any code alteration. If you're open to the idea of supplying a compiler option, I would be interested in making a PR for this."}}