{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/sails/issues/3732","repository_url":"https://api.github.com/repos/balderdashy/sails","labels_url":"https://api.github.com/repos/balderdashy/sails/issues/3732/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/sails/issues/3732/comments","events_url":"https://api.github.com/repos/balderdashy/sails/issues/3732/events","html_url":"https://github.com/balderdashy/sails/issues/3732","id":154986657,"number":3732,"title":"Placing node_modules outside project directory breaks Sails","user":{"login":"jeff-kilbride","id":14877960,"avatar_url":"https://avatars.githubusercontent.com/u/14877960?v=3","gravatar_id":"","url":"https://api.github.com/users/jeff-kilbride","html_url":"https://github.com/jeff-kilbride","followers_url":"https://api.github.com/users/jeff-kilbride/followers","following_url":"https://api.github.com/users/jeff-kilbride/following{/other_user}","gists_url":"https://api.github.com/users/jeff-kilbride/gists{/gist_id}","starred_url":"https://api.github.com/users/jeff-kilbride/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeff-kilbride/subscriptions","organizations_url":"https://api.github.com/users/jeff-kilbride/orgs","repos_url":"https://api.github.com/users/jeff-kilbride/repos","events_url":"https://api.github.com/users/jeff-kilbride/events{/privacy}","received_events_url":"https://api.github.com/users/jeff-kilbride/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-05-16T08:49:30Z","updated_at":"2016-06-17T16:06:34Z","closed_at":null,"body":"<!--\r\n======================================================\r\nHELLO, and welcome to the (experimental) Sailsbot\r\nissue-submission system.  If you encounter any\r\nproblems with this system, please contact\r\nsgress454@treeline.io\r\n\r\nFIRST THINGS FIRST: before posting, please carefully \r\nread the contribution guide (http://bit.ly/sails-issue-guide), \r\nparticularly if this is a security issue or an issue of a \r\nnon-technical nature (Github org issues, code of conduct\r\nissues, etc.).  Those should be sent directly to inquiries@treeline.io.\r\n\r\nNOW THEN: please fill out the following info \r\n(Don't change text between **) \r\n======================================================\r\n### BEGIN VERSION INFO ###\r\n-->\r\n\r\n**Sails version**: 0.12.3\r\n**Node version**: 5.11.0\r\n**NPM version**: 3.9.0\r\n**Operating system**: Docker / Alpine Linux\r\n\r\n<!-- \r\n### END VERSION INFO ###\r\n======================================================\r\nGREAT! - Now read carefully \r\n(Sailsbot will know if you don't)!  \r\n======================================================\r\n\r\nBefore you submit an issue for Sails, please make sure you have read the issue contribution guide (http://bit.ly/sails-issue-guide) carefully, and then verify the following by typing an X in between each set of [ ] brackets below (don't make any other changes to the text!):\r\n\r\n### BEGIN PLEDGE ###\r\n- [X ] I am experiencing a concrete technical issue (aka a bug) with Sails (ideas and feature proposals should follow the guide for proposing features and enhancements (http://bit.ly/sails-feature-guide), which involves making a pull request).  If you're not 100% certain whether it's a bug or not, that's okay--you may continue.  The worst that can happen is that the issue will be closed and we'll point you in the right direction.\r\n\r\n- [X ] I am not asking a question about how to use Sails or about whether or not Sails has a certain feature (please refer to the documentation(http://sailsjs.org), or post on http://stackoverflow.com, our Google Group (http://bit.ly/sails-google-group) or our live chat (https://gitter.im/balderdashy/sails).\r\n\r\n- [X ] I have already searched for related issues, and found none open (if you found a related _closed_ issue, please link to it in your post).\r\n\r\n- [X ] My issue title is concise, on-topic and polite (\"jst.js being removed from layout.ejs on lift\" is good; \"templates dont work\" or \"why is sails dumb\" are not so good).\r\n\r\n- [X ] I have tried all the following (if relevant) and my issue remains:\r\n  - Make sure you have the right app lifted.\r\n  - Make sure you've killed the Sails server with CTRL+C and started it again.\r\n  - Make sure you closed any open browser tabs pointed at localhost before starting Sails.\r\n  - Make sure you do not have any other Sails apps running in other terminal windows.\r\n  - Make sure the app you are using to reproduce the issue has a clean node_modules/ directory, meaning:\r\n    * no dependencies are linked (e.g. you haven't run npm link foo)\r\n    * that you haven't made any inline changes to files in the node_modules/ folder\r\n    * that you don't have any weird global dependency loops. The easiest way to double-check any of the above, if you aren't sure, is to run: rm -rf node_modules && npm cache clear && npm install.\r\n\r\nand finally...\r\n- [X ] **I can provide steps to reproduce this issue that others can follow.**\r\n\r\nIdeally, this involves creating a new repo that demonstrates the problem (see instructions at http://bit.ly/sails-issue-repro).  Even though your issue may seem so simple to reproduce that a new repo is unnecessary, you'd be surprised how many solutions present themselves when you start from `sails new` and attempt to recreate your issue from scratch in a new app.  This ensures that the real issue isn't in your user code (a forgotten policy file, perhaps?) or in a third-party module.  If you're absolutely _convinced_ that a new repo is unnecessary, provide clear, concise and _specific_ steps to reproduce the problem in your post (not \"create a model then do blueprint create\").\r\n### END PLEDGE ###\r\n\r\nOKAY--THANKS FOR READING!  Continue posting details of your issue below. -->\r\n<hr/>\r\n\r\nSee also closed issue #2505.\r\n\r\nSails breaks when the node_modules directory is outside the project directory. In my case, I have installed node_modules one level above my project source. Node is supposed to walk up the filesystem looking for matching node_modules directories.\r\n\r\nThis is extremely important when creating an isolated development environment in Docker. It is a Docker best practice to inject development code into a container by mounting a local volume from the Host. Requiring the node_modules directory to be inside the project directory means that any developer working on my source must install node, npm, and all the dependencies locally -- which defeats the purpose of running a Docker development environment. More importantly, the container is forced to use the local system's node_modules. If there are any modules that have native dependencies, this setup will not work cross-platform. (again, defeating the purpose of Docker...)\r\n\r\nTo recreate this issue, simply take any working sails project and move the node_modules directory up one level. I received the following errors when I did so:\r\n\r\n```\r\ninfo: Could not find module: ejs in path: /app/src/node_modules\r\nerror: A hook (`session`) failed to load!\r\nerror: Could not load Connect session adapter :: connect-redis\r\n\r\nError from adapter:\r\nError: Cannot find module '/app/src/node_modules/connect-redis'\r\n    at Function.Module._resolveFilename (module.js:339:15)\r\n    at Function.Module._load (module.js:290:25)\r\n    at Module.require (module.js:367:17)\r\n    at require (internal/module.js:20:19)\r\n    at Hook.SessionHook.initialize (/app/node_modules/sails/lib/hooks/session/index.js:163:32)\r\n    at Hook.wrapper [as initialize] (/app/node_modules/sails/node_modules/lodash/index.js:3095:19)\r\n    at /app/node_modules/sails/lib/hooks/index.js:74:16\r\n    at /app/node_modules/sails/node_modules/async/lib/async.js:52:16\r\n    at /app/node_modules/sails/node_modules/async/lib/async.js:548:17\r\n    at /app/node_modules/sails/node_modules/async/lib/async.js:542:17\r\n    at _arrayEach (/app/node_modules/sails/node_modules/async/lib/async.js:85:13)\r\n    at Immediate.taskComplete (/app/node_modules/sails/node_modules/async/lib/async.js:541:13)\r\n    at tryOnImmediate (timers.js:534:15)\r\n    at processImmediate [as _immediateCallback] (timers.js:514:5)\r\n\r\nDo you have the Connect session adapter installed in this project?\r\nTry running the following command in your project's root directory:\r\nnpm install connect-redis\r\n(Note: Make sure the version of the Connect adapter you install is compatible with Express 3/Sails v0.10)\r\n\r\nerror: A hook (`orm`) failed to load!\r\nerror: ** Grunt :: An error occurred. **\r\nerror:\r\n------------------------------------------------------------------------\r\nAborted due to warnings.\r\n>> Local Npm module \"grunt-contrib-clean\" not found. Is it installed?\r\n>> Local Npm module \"grunt-contrib-coffee\" not found. Is it installed?\r\n>> Local Npm module \"grunt-contrib-concat\" not found. Is it installed?\r\n>> Local Npm module \"grunt-contrib-copy\" not found. Is it installed?\r\n>> Local Npm module \"grunt-contrib-cssmin\" not found. Is it installed?\r\n>> Local Npm module \"grunt-contrib-jst\" not found. Is it installed?\r\n>> Local Npm module \"grunt-contrib-less\" not found. Is it installed?\r\n>> Local Npm module \"grunt-sails-linker\" not found. Is it installed?\r\n>> Local Npm module \"grunt-sync\" not found. Is it installed?\r\n>> Local Npm module \"grunt-contrib-uglify\" not found. Is it installed?\r\n>> Local Npm module \"grunt-contrib-watch\" not found. Is it installed?\r\nWarning: Task \"watch\" not found.\r\n------------------------------------------------------------------------\r\n\r\nerror: Looks like a Grunt error occurred--\r\nerror: Please fix it, then **restart Sails** to continue running tasks (e.g. watching for changes in assets)\r\nerror: Or if you're stuck, check out the troubleshooting tips below.\r\n\r\nerror: Troubleshooting tips:\r\nerror:\r\nerror:  *-> Are \"grunt\" and related grunt task modules installed locally?  Run `npm install` if you're not sure.\r\nerror:\r\nerror:  *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.\r\nerror:\r\nerror:  *-> Or maybe you don't have permissions to access the `.tmp` directory?\r\nerror:      e.g., `/app/src/.tmp` ?\r\nerror:\r\nerror:      If you think this might be the case, try running:\r\nerror:      sudo chown -R YOUR_COMPUTER_USER_NAME /app/src/.tmp\r\n```\r\n\r\nSymlinking the node_modules directory, as discussed in the closed issue I referenced earlier, will not help. When you inject a local Host volume into a container, the Host volume overlays the existing content in the container. Therefore, any symlink would also be masked from the container. For anyone not familiar with Docker, the idea would be to have a directory layout like the following in the container:\r\n\r\n```\r\n-- app\r\n    -- node_modules\r\n    -- src\r\n```\r\n\r\nWith this structure, you can inject the `app/src` directory from the Host without disturbing the dependencies and without requiring anything but the project source files on the Host. Please see https://docs.docker.com/engine/userguide/containers/dockervolumes/#mount-a-host-directory-as-a-data-volume for more info.\r\n"},"comment":{"url":"https://api.github.com/repos/balderdashy/sails/issues/comments/226811013","html_url":"https://github.com/balderdashy/sails/issues/3732#issuecomment-226811013","issue_url":"https://api.github.com/repos/balderdashy/sails/issues/3732","id":226811013,"user":{"login":"jeff-kilbride","id":14877960,"avatar_url":"https://avatars.githubusercontent.com/u/14877960?v=3","gravatar_id":"","url":"https://api.github.com/users/jeff-kilbride","html_url":"https://github.com/jeff-kilbride","followers_url":"https://api.github.com/users/jeff-kilbride/followers","following_url":"https://api.github.com/users/jeff-kilbride/following{/other_user}","gists_url":"https://api.github.com/users/jeff-kilbride/gists{/gist_id}","starred_url":"https://api.github.com/users/jeff-kilbride/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeff-kilbride/subscriptions","organizations_url":"https://api.github.com/users/jeff-kilbride/orgs","repos_url":"https://api.github.com/users/jeff-kilbride/repos","events_url":"https://api.github.com/users/jeff-kilbride/events{/privacy}","received_events_url":"https://api.github.com/users/jeff-kilbride/received_events","type":"User","site_admin":false},"created_at":"2016-06-17T16:06:34Z","updated_at":"2016-06-17T16:06:34Z","body":"@stanislavromanov \r\n\r\nThanks! Yeah, I've been considering doing that myself. I've dug around in the code a bit before to help chase down a problem with the way models were handling email addresses. That issue got resolved relatively quickly, but that was a while ago. I've looked at your commit. What bothers me is that, from your example, this seems like a simple fix -- don't prepend the project path to the `require` statement. But who knows if there are other gotchas or if this was done for a reason at some point in the past.\r\n\r\nMy bigger issue is the fact that sails isn't updating. I've taken the time to learn sails and I really like everything it does. I even recommend it to others when starting new projects. However, I'm not comfortable relying on it for production when there's little participation and the issues board is a ghost town. I'm not trying to be a jerk pointing this stuff out. I think it's a legitimate concern. There are a ton of node / javascript frameworks. There are even other languages I want to explore, like Go. I hate the idea of walking away from the time I've spent in the sails learning curve, but I also don't want to wind up maintaining my own fork by myself. Not getting any response here makes it easier to choose something else."}}
{"actor":{"display_login":"jeff-kilbride"}}