Johnil Quezada
Johnil Quezada

Reputation: 71

serverless-webpack Cannot find module './node/NodeTemplatePlugin'

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!

Upvotes: 3

Views: 1313

Answers (1)

Eloy Pineda
Eloy Pineda

Reputation: 2187

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

Upvotes: 1

Related Questions