代码之家  ›  专栏  ›  技术社区  ›  SamBrick

网页包和AWS Lambda问题-模块上缺少处理程序

  •  13
  • SamBrick  · 技术社区  · 7 年前

    Handler 'handler' missing on module 'dist/main'
    

    这是我的网页。配置。js公司-

    const path = require('path');
    
    module.exports = {
      entry: './index.js',
      output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'main.js',
        libraryTarget: 'commonjs'
      },
      module: {
        rules: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            options: {
              plugins: [require('babel-plugin-transform-flow-strip-types')],
              presets: [
                [
                  'env',
                  {
                    target: { node: 6.10 }, // Node version on AWS Lambda
                    useBuiltIns: false,
                    loose: false,
                    exclude: [],
                    debug: false
                  },
                ],
              ],
            },
          }
        ],
      }
    };
    

    这里是编译后的main的一个片段。js公司-

    /***/ (function(module, exports, __webpack_require__) {
    
    "use strict";
    
    Object.defineProperty(exports, "__esModule", {
        value: true
    });
    exports.handler = handler;
    
    var _amazonCognitoIdentityJs = __webpack_require__(60);
    
    var _aws_profile = __webpack_require__(290);
    
    // A signin Lambda function
    function handler(event, context, callback) {
            switch (event.httpMethod) {
            case "GET":
    

    一点背景。。。。这是我最初编写的Lambda,不是在ES6中,也不是使用Webpack绑定的,它是有效的。我现在需要它在ES6和网页包的工作。N、 B.这是网页2

    非常感谢。。。

    2 回复  |  直到 7 年前
        1
  •  18
  •   SamBrick    7 年前

    为了解决这个问题,我必须指定一个library属性,并将libraryTarget更改为commonjs2。网页包。配置。js文件输出现在如下所示-

    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'main.js',
        library: 'main',
        libraryTarget: 'commonjs2'
      },
    
        2
  •  9
  •   Ted_Zactly    2 年前

    我也遇到了这个问题。然而,我相信我的处境与SamBrick所分享的恰恰相反。我正在从使用babel传输ES6转移到在lambda/node 6.10上运行,到不传输和针对lambda/node 8.10。卸下 library 字段并更改为 libraryTarget: 'commonjs' 帮我解决了这个问题。

    这家伙的道具: https://gist.github.com/nirnanaaa/d7f40deb38f1cf7f931dc7ef0c582bf0