I’ve set up my project according to the serverless-webpack
docs. My functions (written in ES6) work when invoked locally, but result in the following error when I deploy them to AWS:
{
"errorMessage": "Unexpected token import",
"errorType": "SyntaxError",
"stackTrace": [
"SyntaxError: Unexpected token import",
"createScript (vm.js:56:10)",
"Object.runInThisContext (vm.js:97:10)",
"Module._compile (module.js:542:28)",
"Object.Module._extensions..js (module.js:579:10)",
"Module.load (module.js:487:32)",
"tryModuleLoad (module.js:446:12)",
"Function.Module._load (module.js:438:3)",
"Module.require (module.js:497:17)",
"require (internal/module.js:20:19)"
]
}
My current understanding is that Lambda should have recompiled the ES6 code according to my webpack.config.js settings before actually executing the code, but that doesn’t appear to be the case. Does anyone have any pointers?
webpack.config.js:
const path = require(‘path’);
const slsw = require(‘serverless-webpack’);
const nodeExternals = require(“webpack-node-externals”);
module.exports = {
entry: slsw.lib.entries,
target: 'node',
mode: 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
}
]
},
externals: [nodeExternals(), 'pg', 'sqlite3', 'tedious', 'pg-hstore'],
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
}
};
.babelrc:
{
“passPerPreset”: true,
“presets”: [
{ “plugins”: [ “transform-runtime” ] },
{
“passPerPreset”: false,
“presets”: [ “env”, “stage-3” ]
}
]
}