Skip to content

Instantly share code, notes, and snippets.

@compwright compwright/README.md
Last active Dec 12, 2019

Embed
What would you like to do?
AnomalyInnovations/serverless-bundle test case

Test case for:

https://github.com/AnomalyInnovations/serverless-bundle/issues/12 (sharp)

https://github.com/AnomalyInnovations/serverless-bundle/issues/2 (redis)

$ node -v
v12.12.0
$ npm install
added 1371 packages in 37.322s
$ npx serverless package
Serverless: Bundling with Webpack...

ERROR in /Users/jhill/Downloads/serverless-bundle-test/node_modules/redis-parser/lib/hiredis.js
Module not found: Error: Can't resolve 'hiredis' in '/Users/jhill/Downloads/serverless-bundle-test/node_modules/redis-parser/lib'
 @ /Users/jhill/Downloads/serverless-bundle-test/node_modules/redis-parser/lib/hiredis.js 3:14-32
 @ /Users/jhill/Downloads/serverless-bundle-test/node_modules/redis-parser/lib/parser.js
 @ /Users/jhill/Downloads/serverless-bundle-test/node_modules/redis-parser/index.js
 @ /Users/jhill/Downloads/serverless-bundle-test/node_modules/redis/index.js
 @ /Users/jhill/Downloads/serverless-bundle-test/handler.js
 
  Error --------------------------------------------------
 
  Error: Webpack compilation error, see above
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/serverless-webpack/lib/compile.js:38:19
      at arrayEach (/Users/jhill/Downloads/serverless-bundle-test/node_modules/lodash/lodash.js:516:11)
      at Function.forEach (/Users/jhill/Downloads/serverless-bundle-test/node_modules/lodash/lodash.js:9342:14)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/serverless-webpack/lib/compile.js:31:11
      at tryCatcher (/Users/jhill/Downloads/serverless-bundle-test/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/jhill/Downloads/serverless-bundle-test/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/Users/jhill/Downloads/serverless-bundle-test/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/jhill/Downloads/serverless-bundle-test/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/jhill/Downloads/serverless-bundle-test/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/jhill/Downloads/serverless-bundle-test/node_modules/bluebird/js/release/promise.js:673:18)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/bluebird/js/release/nodeback.js:42:21
      at finalCallback (/Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/MultiCompiler.js:254:12)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/MultiCompiler.js:277:6
      at done (/Users/jhill/Downloads/serverless-bundle-test/node_modules/neo-async/async.js:2931:13)
      at runCompilers (/Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/MultiCompiler.js:181:48)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/MultiCompiler.js:188:7
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/MultiCompiler.js:270:7
      at finalCallback (/Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compiler.js:257:39)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compiler.js:273:13
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/Hook.js:154:20)
      at onCompiled (/Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compiler.js:271:21)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compiler.js:681:15
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/Hook.js:154:20)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compiler.js:678:31
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/Hook.js:154:20)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compilation.js:1423:35
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/Hook.js:154:20)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compilation.js:1414:32
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/Hook.js:154:20)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compilation.js:1409:36
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/Hook.js:154:20)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compilation.js:1405:32
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/Hook.js:154:20)
      at Compilation.seal (/Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compilation.js:1342:27)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compiler.js:675:18
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compilation.js:1261:4
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
      at AsyncSeriesHook.lazyCompileHook (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/Hook.js:154:20)
      at Compilation.finish (/Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compilation.js:1253:28)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compiler.js:672:17
      at eval (eval at create (/Users/jhill/Downloads/serverless-bundle-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compilation.js:1185:12
      at /Users/jhill/Downloads/serverless-bundle-test/node_modules/webpack/lib/Compilation.js:1097:9
      at processTicksAndRejections (internal/process/task_queues.js:75:11)
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.12.0
     Framework Version:         1.59.3
     Plugin Version:            3.2.5
     SDK Version:               2.2.1
     Components Core Version:   1.1.2
     Components CLI Version:    1.4.0
$ 

Bundling works with serverless v1.59.3, sharp v0.23.4, and serverless-bundle v1.3.0-beta.2

Build rebuilds the correct sharp binary for AWS Lambda

Build properly excludes the built-in aws-sdk package

Build still fails with redis

const AWS = require('aws-sdk'); // eslint-disable-line no-unused-vars
const sharp = require('sharp'); // eslint-disable-line no-unused-vars
const redis = require('redis'); // eslint-disable-line no-unused-vars
module.exports.hello = async event => {
await AWS.config.credentials.get();
return {
statusCode: 200,
body: JSON.stringify(
{
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
},
null,
2
),
};
};
{
"name": "serverless-bundle-test",
"version": "1.0.2",
"description": "",
"main": "handler.js",
"scripts": {
"reset": "rm -Rf node_modules package-lock.json && npm run clean",
"clean": "rm -Rf .serverless .webpack",
"build": "npx serverless package"
},
"keywords": [],
"author": "Jonathon Hill",
"license": "MIT",
"devDependencies": {
"aws-sdk": "^2.588.0",
"serverless": "^1.59.3",
"serverless-bundle": "^1.3.0-beta.2"
},
"dependencies": {
"redis": "^2.8.0",
"sharp": "^0.23.4"
}
}
service: serverless-bundle-test
plugins:
- serverless-bundle
custom:
bundle:
sourcemaps: false
caching: true
linting: true
packagerOptions:
scripts:
- npm rebuild sharp --arch=x64 --platform=linux --target=12.13.0
package:
individually: true
provider:
name: aws
runtime: nodejs12.x
functions:
hello:
handler: handler.hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.