【问题标题】:serverless-webpack Cannot find module './node/NodeTemplatePlugin'serverless-webpack 找不到模块'./node/NodeTemplatePlugin'
【发布时间】:2019-11-25 07:29:41
【问题描述】:

我正在尝试使用 serverless-webpack plugin,虽然单独运行 webpack 工作正常,但尝试运行 serverless-webpack 失败并出现 Cannot find module './node/NodeTemplatePlugin'

我的 serverless.yml 文件如下:

service: kamehameha

provider:
  name: aws
  runtime: nodejs6.10

functions:
  getDeltas:
    handler: bundle.getDeltas

plugins:
  - serverless-webpack

我的 webpack 配置如下:

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 单独将原因文件编译成 bundle.js,但是 serverless-webpack 运行时出现上述错误。

我正在尝试使用该插件,因为单独编译和部署会导致无法找到处理程序的 lambda 错误。

我尝试删除全局 webpack 安装并仅使用本地安装,以及无服务器。有没有人遇到过类似的情况?

谢谢!

【问题讨论】:

  • 你试过声明package: individually: true吗?
  • @TrentBartlem 现在我做到了。不幸的是,这并没有解决它。

标签: webpack serverless-framework


【解决方案1】:

确保您的 serverless.ymlcustom 部分的 webpack 配置中有 includeModules: true 设置。

来自serverless-webpack 文档:

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

【讨论】:

    猜你喜欢
    • 2020-09-14
    • 2021-07-13
    • 2017-08-12
    • 2017-04-15
    • 2021-11-04
    • 2020-12-12
    • 2021-10-27
    • 1970-01-01
    相关资源
    最近更新 更多