LoginSignup
1
0

More than 5 years have passed since last update.

serverless-webpackのwebpack.config.jsでハマった話

Posted at

なにがあったの

sls deployしたlambdaのテストしたらHandler 'say' missing on module 'hello'と怒られた。

問題のwebpack.config.js

var nodeExternals = require('webpack-node-externals')

module.exports = {
    entry: './src/handler.js',
    target: 'node',
    output: {path: 'dist'},
    externals: [nodeExternals()],
};

出てきたコード

/******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};
以下略

望んでいたコード

(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};
以下略

お分かりいただけただろうか。
output: {path: 'xxx' }で指定するとglobalのexportsを渡してくれなくなるのである。

とりあえずの対応

と言うかserverless frameworkで作るAPIなので、複数ファイルで管理していた。
そのため、
entry: {file1: './src/create.js', file2: './src/list.js'}
のようにしていたので、outputが必須だった。

とりあえず、arrayで渡せばoutputは必要なくなるので、暫定対応として。
enrty: ['./src/create.js', './src/list.js']

各lambda functionの中身を微調整する必要は出てきたが、是非もないネ!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0