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

江枫思渺然 提交于 2019-12-13 13:51:40

问题


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!


回答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


来源:https://stackoverflow.com/questions/44812204/serverless-webpack-cannot-find-module-node-nodetemplateplugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!