SLS deploy failing from CD but working from local

aws

#1

I’ve been using Bitbucket Pipelines to deploy Serverless Framework services to AWS for some time now.

Recently, one of my services began throwing an error upon invocation after being deployed through Pipelines:

Syntax error in module ‘index’: SyntaxError
async _initialize() {
^^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions…js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/var/task/node_modules/keras-js/lib/index.js:22:37)
at Module._compile (module.js:570:32)
at Object.Module._extensions…js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)

However, when I deploy the same service from the command line (sls deploy -s staging), the invocation works correctly.

The relevant part of the deploy script:

  • npm update npm@5.6.0 -g
  • npm install -g serverless@1.17.0
  • export SLS_STAGE=staging
  • export AWS_PROFILE=staging
  • serverless config credentials -p aws -k $AWS_KEY -s $AWS_SECRET --profile $AWS_PROFILE
  • npm install
  • sls deploy -s $SLS_STAGE -r $AWS_REGION

The error refers to “/var/task/node_modules/keras-js/lib/index.js” which is nowhere in my package-lock.json.

Also, I noticed that the package size of the Pipelines generated package was much larger than the locally generated package (roughly 11MB vs 5MB).

Any ideas? I have spent a few hours on this and am getting nowhere.