External node module not being packed

Hi all!

I’m trying to deploy some functions that use Ramda but for some reason that package is not being bundled in the .serverless folder. It reports that it is bundling the module but somehow it just never gets into the .zip file. There are no reported errors or anything that would lead me to believe that it couldn’t find it. I thought it was ok until I saw the error log in AWS. I saw External Npm modules cannot be referenced v1.0(Bug) but that seems to have been user error (which hopefully this is as well).

Relevant output from sls deploy --noDeploy

$ SLS_DEBUG=* sls deploy "--noDeploy"
Serverless: WARNING: Plugin ServerlessWebpack uses deprecated hook before:deploy:createDeploymentArtifacts
Serverless: WARNING: Plugin ServerlessWebpack uses deprecated hook after:deploy:createDeploymentArtifacts
Serverless: Bundling with Webpack...
Time: 2705ms
   Asset     Size  Chunks             Chunk Names
handlers  36.2 kB       0  [emitted]  main
Serverless: Packing external modules: ramda@0.24.1, auth0@2.7.0, bluebird@^3.5.0, http-status@1.0.1, uuid@^3.1.0,
@google-cloud/language@0.10.6, watson-developer-cloud@2.33.0
Serverless: Packaging service...
Serverless: Publish service to Serverless Platform...
Serverless: Couldn't publish this deploy information to the Serverless Platform.

  Error --------------------------------------------------

  GraphQL error: Lambda services-publishService threw an Error during invokation

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

Error: GraphQL error: Lambda services-publishService threw an Error during invokation
    at new ApolloError (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/apollo-client/apollo.umd.
js:2059:28)
    at /Users/john/repos/hashback.io/feedback-analysis-api/node_modules/apollo-client/apollo.umd.js:2772:33
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:208:7)
From previous event:
    at fetchEndpoint.then.endpoint (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serverless/li
b/plugins/platform/platform.js:161:16)
From previous event:
    at provider.getAccountId.then.accountId (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serv
erless/lib/plugins/platform/platform.js:112:51)
From previous event:
    at fetchEndpoint.then.endpoint (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serverless/li
b/plugins/platform/platform.js:161:16)
From previous event:
    at provider.getAccountId.then.accountId (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serv
erless/lib/plugins/platform/platform.js:112:51)
From previous event:
    at Platform.publishService (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serverless/lib/pl
ugins/platform/platform.js:111:41)
    at BbPromise.reduce (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serverless/lib/classes/P
luginManager.js:217:55)
From previous event:
    at PluginManager.invoke (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serverless/lib/class
es/PluginManager.js:217:22)
    at PluginManager.run (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serverless/lib/classes/
PluginManager.js:236:17)
    at variables.populateService.then (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serverless
/lib/Serverless.js:107:33)
    at runCallback (timers.js:800:20)
    at tryOnImmediate (timers.js:762:5)
    at processImmediate [as _immediateCallback] (timers.js:733:5)
From previous event:
    at Serverless.run (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serverless/lib/Serverless.
js:94:74)
    at serverless.init.then (/Users/john/repos/hashback.io/feedback-analysis-api/node_modules/serverless/bin/serve
rless:30:50)
    at <anonymous>
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.1.3
     Serverless Version:     1.16.1

error Command failed with exit code 1.

I don’t think the error at the end is related to this issue. I brought it up in another topic

package.json inside .zip file

{
  "dependencies": {
    "@google-cloud/language": "^0.10.6",
    "auth0": "^2.7.0",
    "bluebird": "^3.5.0",
    "http-status": "^1.0.1",
    "ramda": "^0.24.1",
    "uuid": "^3.1.0",
    "watson-developer-cloud": "^2.33.0"
  }
}

webpack.config.js

const nodeExternals = require('webpack-node-externals');

module.exports = {
  entry: './src/handlers.js',
  externals: [nodeExternals()],
  module: {
    loaders: [
      {
        exclude: /node_modules/,
        loaders: ['babel-loader'],
        test: /\.jsx?$/,
      },
    ],
  },
  output: {
    filename: 'handlers',
    libraryTarget: 'commonjs',
    path: '.webpack/src',
  },
  target: 'node',
};

.babelrc

{
  "presets": [
    "es2015",
    "flow",
    "stage-2"
  ],
  "plugins": [
    [
      "transform-builtin-extend",
      {
        "globals": ["Error"]
      }
    ],
    "ramda",
    "add-module-exports",
    "transform-decorators-legacy"
  ]
}

*Note that removing the "ramda" plugin from babel does not fix the issue.

(partial) serverless.yml

custom:
  webpackIncludeModules:
    packagePath: './package.json'

Turns out this is a bug in NodeJS v8.1 (https://github.com/nodejs/node/issues/12921) Downgrading my deploy environment to 6.10 fixes the issue

1 Like