错误:ENOENT:在无服务器项目中尝试在lambda函数内部导入ejs文件时,没有此类文件或目录

时间:2019-07-04 18:43:17

标签: webpack ejs serverless

在我的lambda函数之一中,我尝试使用SES发送电子邮件,以表示我正在使用ejs的电子邮件正文,以便我可以传递一些数据并将自定义的电子邮件发送给收件人。未使用Webpack配置Serverless时成功。添加webpack后,它返回错误:ENOENT:没有这样的文件或目录。请任何人帮助我找出解决方法。

我尝试在webpack.config.js文件中为ejs文件添加新规则。

const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  // Generate sourcemaps for proper error messages
  devtool: 'source-map',
  // Since 'aws-sdk' is not compatible with webpack,
  // we exclude all node dependencies
  externals: [nodeExternals()],
  mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
  optimization: {
    // We no not want to minimize our code.
    minimize: true,
  },
  performance: {
    // Turn off size warnings for entry points
    hints: false,
  },
  // Run babel on all .js files and skip those in node_modules
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: __dirname,
        exclude: /node_modules/,
      },
      {
        test: /\.ejs$/,
        loader: 'ejs-loader',
        query: {
            variable: 'data',
            interpolate : '\\{\\{(.+?)\\}\\}',
            evaluate : '\\[\\[(.+?)\\]\\]'
        }
      }
    ],
  },
};

1 个答案:

答案 0 :(得分:0)

尝试添加此插件

cityID