{"action":"created","issue":{"url":"https://api.github.com/repos/elastic-coders/serverless-webpack/issues/70","repository_url":"https://api.github.com/repos/elastic-coders/serverless-webpack","labels_url":"https://api.github.com/repos/elastic-coders/serverless-webpack/issues/70/labels{/name}","comments_url":"https://api.github.com/repos/elastic-coders/serverless-webpack/issues/70/comments","events_url":"https://api.github.com/repos/elastic-coders/serverless-webpack/issues/70/events","html_url":"https://github.com/elastic-coders/serverless-webpack/issues/70","id":196680221,"number":70,"title":"Strange behavior with Mongoose","user":{"login":"mrpatiwi","id":7570744,"avatar_url":"https://avatars2.githubusercontent.com/u/7570744?v=3","gravatar_id":"","url":"https://api.github.com/users/mrpatiwi","html_url":"https://github.com/mrpatiwi","followers_url":"https://api.github.com/users/mrpatiwi/followers","following_url":"https://api.github.com/users/mrpatiwi/following{/other_user}","gists_url":"https://api.github.com/users/mrpatiwi/gists{/gist_id}","starred_url":"https://api.github.com/users/mrpatiwi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrpatiwi/subscriptions","organizations_url":"https://api.github.com/users/mrpatiwi/orgs","repos_url":"https://api.github.com/users/mrpatiwi/repos","events_url":"https://api.github.com/users/mrpatiwi/events{/privacy}","received_events_url":"https://api.github.com/users/mrpatiwi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-12-20T14:03:22Z","updated_at":"2017-06-09T13:31:23Z","closed_at":null,"body":"Trying mongoose with `context.callbackWaitsForEmptyEventLoop = false` so the function should end after calling `callback(...)` works different while using `serverless-webpack` as a plugin and when manually packing the project with webpack.\r\n\r\n```js\r\n// webpack.config.js\r\nmodule.exports = {\r\n  entry: './handler.js',\r\n  target: 'node',\r\n  output: {\r\n    libraryTarget: 'commonjs',\r\n    path: 'dist',\r\n    filename: 'handler.js',\r\n  },\r\n\r\n  // Any module with native extensions has to be excluded\r\n  externals: [\r\n    'mongoose',\r\n  ],\r\n}\r\n```\r\n\r\n```js\r\n// handler.js\r\n'use strict';\r\nimport mongoose from 'mongoose';\r\nimport Promise from 'bluebird';\r\n\r\nexport const UserSchema = new mongoose.Schema({\r\n  name: String,\r\n});\r\nconst User = mongoose.model('User', UserSchema);\r\n\r\nconst MONGO_URI = process.env.MONGO_URI || 'mongodb://localhost/lambda';\r\nmongoose.connect(MONGO_URI);\r\n\r\nmodule.exports.handler = (event, context, callback) => {\r\n  context.callbackWaitsForEmptyEventLoop = false\r\n  return User.find({})\r\n    .then(results => callback(null, results))\r\n    .catch(callback);\r\n};\r\n```\r\n\r\n## With `serverless-webpack`\r\n\r\n```yml\r\n# serverless.yml\r\nservice: users\r\n\r\nplugins:\r\n  - serverless-webpack\r\n\r\ncustom:\r\n  webpackIncludeModules: true\r\n\r\nfunctions:\r\n  index:\r\n    handler: handler.handler\r\n    events:\r\n      - http:\r\n          path: users\r\n          method: get\r\n```\r\n\r\nWhen calling the function it gets stuck on some event-loop and eventually it times-out on AWS.\r\n\r\n## Without `serverless-webpack`\r\n\r\n```yml\r\n# serverless.yml\r\nservice: users\r\n\r\npackage:\r\n  include:\r\n    - dist/**\r\n\r\nfunctions:\r\n  index:\r\n    handler: dist/handler.handler\r\n    events:\r\n      - http:\r\n          path: users\r\n          method: get\r\n```\r\n\r\nManually running `webpack` and:\r\n\r\n```sh\r\ncd dist \r\necho \"{}\" > package.json \r\nnpm i --save mongoose\r\ncd ..\r\n```\r\n\r\nAnd then running it locally or on production it work as expected.\r\n"},"comment":{"url":"https://api.github.com/repos/elastic-coders/serverless-webpack/issues/comments/307389177","html_url":"https://github.com/elastic-coders/serverless-webpack/issues/70#issuecomment-307389177","issue_url":"https://api.github.com/repos/elastic-coders/serverless-webpack/issues/70","id":307389177,"user":{"login":"ed-zm","id":6220914,"avatar_url":"https://avatars2.githubusercontent.com/u/6220914?v=3","gravatar_id":"","url":"https://api.github.com/users/ed-zm","html_url":"https://github.com/ed-zm","followers_url":"https://api.github.com/users/ed-zm/followers","following_url":"https://api.github.com/users/ed-zm/following{/other_user}","gists_url":"https://api.github.com/users/ed-zm/gists{/gist_id}","starred_url":"https://api.github.com/users/ed-zm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ed-zm/subscriptions","organizations_url":"https://api.github.com/users/ed-zm/orgs","repos_url":"https://api.github.com/users/ed-zm/repos","events_url":"https://api.github.com/users/ed-zm/events{/privacy}","received_events_url":"https://api.github.com/users/ed-zm/received_events","type":"User","site_admin":false},"created_at":"2017-06-09T13:31:23Z","updated_at":"2017-06-09T13:31:23Z","body":"Any solution for this?\r\n"}}
{"actor":{"display_login":"ed-zm"}}