-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
various npm modules being ignored #424
Comments
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. BTW: I saw a small glitch in your 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 I'd love to hear your thoughts. Also, thanks for the catch on the issue with my |
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 |
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 😃 |
Actually seeing this with dependencies containing |
Here's an example from another function:
|
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 |
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 I appreciate your help with this. Sorry for the runaround! |
Got into this with local packages that obviously have dot symbol TypeError
bundle.jsvar someFunction = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module 'some'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())); index.jsconst serverless = require('serverless-http')
const bodyParser = require('body-parser')
const express = require('express')
const someFunction = require('./some') # <- "some.js"
const app = express()
app.post('/', function (req, res) {
console.log('Entry request body: ', req.body)
res.send({
status: 'ok',
message: someFunction()
})
} some.jsconst someFunction = () => {
return console.log("Works!")
}
module.exports.someFunction = someFunction; .babelrc{
"plugins": [
["transform-runtime", {
"polyfill": false,
"regenerator": true
}]
],
"presets": [
["env", { "modules": false, "targets": { "node": "8.10" }}],
["es2015", { "modules": false }],
["stage-2"]
]
} webpack.config.jsconst path = require('path');
const slsw = require('serverless-webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin')
const nodeExternals = require('webpack-node-externals');
module.exports = {
target: 'node',
entry: slsw.lib.entries,
plugins: [
new CopyWebpackPlugin([{
from: 'assets',
to: 'assets'
}])
],
module: {
rules: [{
exclude: /node_modules/,
test: /\.js$/,
loader: 'babel-loader'
}]
},
stats: {
colors: true
},
devtool: 'source-map',
mode: slsw.lib.webpack.isLocal ? "development" : "production",
optimization: {
minimize: false
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, 'dist'),
filename: '[name].js',
},
externals: [nodeExternals({
whitelist: ['express', /^lodash/]
})]
}; serverless.yml# serverless.yml
frameworkVersion: ">=1.0.0 <2.0.0"
service: awesome-api
custom:
webpack:
includeModules: true
packager: 'yarn'
forceExclude:
- aws-sdk
forceInclude:
- some
functions:
app:
handler: src/index.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'
plugins:
- serverless-webpack
- serverless-offline
- serverless-pseudo-parameters
package:
individually: true |
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
I'm not seeing any errors, but when running
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):
Additional Data
The text was updated successfully, but these errors were encountered: