serverless-webpack 找不到模块 './node/NodeTemplatePlugin' [英] serverless-webpack Cannot find module './node/NodeTemplatePlugin'

查看:37
本文介绍了serverless-webpack 找不到模块 './node/NodeTemplatePlugin'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 serverless-webpack 插件,并且在运行时webpack 单独工作得很好,尝试运行 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'.

我的serverless.yml文件如下:

My serverless.yml file is as follows:

service: kamehameha

provider:
  name: aws
  runtime: nodejs6.10

functions:
  getDeltas:
    handler: bundle.getDeltas

plugins:
  - serverless-webpack

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

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

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

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

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

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

谢谢!

推荐答案

确保您在 custom 部分的 webpack 配置中有 includeModules: true 设置代码>serverless.yml.

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

来自 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

这篇关于serverless-webpack 找不到模块 './node/NodeTemplatePlugin'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆