Closed jamesdixon closed 6 years ago
Hi @jamesdixon , the plugin only packages dependencies that are used by the function code you deploy. These dependencies are detected by webpack and reported to the plugin. As a consequence the plugin only bundles dependencies that are reported by Webpack. So you get the best dependency optimization possible for each single function. Maybe webpack bundled some dependencies into the code - or it is not used in the code paths used for the functions. If the deployed code works properly this is a sign, that Webpack did it's job very well 😄 .
BTW: I saw a small glitch in your serverless.yml
. You should correct the plugin order, because it matters when initializing the plugins:
plugins:
- serverless-webpack
- serverless-offline
- serverless-plugin-deploy-environment
It is very important that sls-webpack is first, because offline should run the compiled code.
Hi @HyperBrain - first, thank you for taking the time to reply! It's much appreciated.
I probably should have been more clear in my report. Various npm modules are not being included, which in turn is causing my functions to fail. I mentioned the previous issue with lodash.*
functions not being included. Rather than import all of lodash, I've just been grabbing individual packages, such as lodash.chunk
. When I run sls package
, I see that the lodash
library is included in full, but not the individual functions. I'm guessing one of my dependencies includes lodash
and webpack sees that lodash.chunk
is part of lodash
and decides not to include it? If that is the case, my code calls require('lodash.chunk')
which is why the error is being thrown.
I'd love to hear your thoughts.
Also, thanks for the catch on the issue with my serverless.yml
file!
I just opened up my handler that's output after packaging and noticed the following lines:
const AWS = __webpack_require__(7)
const Joi = __webpack_require__(6)
const KnexConfig = __webpack_require__(5)
const Knex = __webpack_require__(4)(KnexConfig["production"])
const SendGrid = __webpack_require__(3)
const UUID = __webpack_require__(2)
const { configureRollbar } = __webpack_require__(1)
const chunk = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module 'lodash.chunk'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()))
It looks like webpack can't find lodash.chunk
? So confused...lol
Indeed - it is really a missing dependency. Maybe it's a bug in the plugin with dependency names containing a dot? I never used such names 😃
We should test, if other dependencies of the format xxx.yyy
are also dropped silently.
Actually seeing this with dependencies containing -
. Going to see if there are other cases...
Here's an example from another function:
const AWS = __webpack_require__(7)
const Email = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module 'email-templates'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()))
const Joi = __webpack_require__(6)
const Path = __webpack_require__(5)
const Redis = __webpack_require__(4)
const cachePugTemplates = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module 'cache-pug-templates'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()))
const { configureRollbar } = __webpack_require__(3)
const { getEnvPrefix } = __webpack_require__(1)
Hmmm... It is strange that the missing modules are already "compiled" into the code. This hints to an issue with the webpack configuration, because otherwise they would only be missing in the deployed package, but not the compiled code, wouldn't they?
I suppose so. My webpack knowledge is very very limited 😄
I don't have any of the output
or babel
related code in my config. Is it something that's required?
Maybe yes - I never used webpack without babel (and the babel loader). Maybe you can check the webpack4 example in the examples folder (of the plugin repo) and use that to setup a second variant of your project to see if that works.
@HyperBrain finally got this working!
It turns out the issue was actually with the Webpack.IgnorePlugin
calls in my webpack config. I had originally added those due to errors I was getting when building. For some reason, those errors no longer exist now that I've removed the plugins.
I appreciate your help with this. Sorry for the runaround!
Got into this with local packages that obviously have dot symbol
This is a (Bug Report / Feature Proposal)
Maybe a bug, maybe a misunderstanding
Description
For bug reports:
Many of my modules defined under dependencies aren't being included in the build. For example, none of the
lodash.*
dependencies are included.All modules should be included in the build
sls deploy --stage beta
, I see the following:Serverless: Package lock found - Using locked versions Serverless: Packing external modules: @sendgrid/mail@^6.3.1, joi@^13.4.0, rollbar@^2.4.2, redis@^2.8.0, @sendgrid/client@^6.3.0, knex@^0.15.0 Serverless: Packaging service...
You can see this is just a small subset of my dependencies.
For feature proposals:
Similar or dependent issue(s):
408
Additional Data