3

I'm trying to use the serverless-webpack plugin, and while running webpack alone works just fine, attempting to run serverless-webpack fails with Cannot find module './node/NodeTemplatePlugin'.

My serverless.yml file is as follows:

service: kamehameha

provider:
  name: aws
  runtime: nodejs6.10

functions:
  getDeltas:
    handler: bundle.getDeltas

plugins:
  - serverless-webpack

And my webpack config is as follows:

let path = require("path")
let webpack = require("webpack")
let nodeExternals = require("webpack-node-externals")

module.exports = {
  entry: "./src/index.re",
  target: "node",
  node: {
    __dirname: true,
  },
  externals: [nodeExternals()],
  output: {
    path: __dirname,
    filename: "bundle.js",
  },
  module: {
    loaders: [
      {
        test: /\.re$/,
        loader: "bs-loader",
      },
    ],
  },
  resolve: {
    extensions: [".re", ".ml", ".js"],
  },
}

Webpack alone compiles the reason file into bundle.js, however serverless-webpack runs with the aforemention error.

I'm trying to use the plugin because compiling and deploying alone causes a lambda error where it cannot find the handler.

I've tried removing the global webpack installation and using only the local one, as well as with serverless. Has anyone encountered something similar?

Thanks!

2
  • Have you tried declaring package: individually: true ? Commented Jun 28, 2017 at 23:43
  • 1
    @TrentBartlem Now I did. Unfortunately that did not fix it. Commented Jul 1, 2017 at 0:51

1 Answer 1

1

Make sure you have includeModules: true setting in the webpack configuration within the custom section in your serverless.yml.

From serverless-webpack documentation:

custom:
  webpack:
    webpackConfig: 'webpack.config.js'   # Name of webpack configuration file
    includeModules: false   # Node modules configuration for packaging
    packager: 'npm'   # Packager that will be used to package your external modules
    excludeFiles: src/**/*.test.js # Provide a glob for files to ignore
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.