serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack
MIT License
1.72k stars 414 forks source link

Support Node 14 / ES2020 #693

Open henhal opened 3 years ago

henhal commented 3 years ago

This is a Feature Request

Description

AWS is deprecating Node 10 in April, so we've converted all our lambdas, and we then went straight to Node 14. Node 14 enables using some new features, so while at it I updated my tsconfig.json to transpile to ES2020 instead of ES2019:

"compilerOptions": {
  "target": "ES2020",
  ...
}

When doing so, serverless-bundle failed to deploy my lambdas, supposedly because serverless-webpack does not support ES2020:

ERROR in <snip>/node_modules/<snip>/dist/<snip>.js 184:33
   Module parse failed: Unexpected token (184:33)
   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
   >             body = body ?? result;

Now, obviously I can run Node 14 with TS transpiled down to ES2019; since I use TS I get the nice new features anyway so to speak and it's not really critical what level the transpiled code has as long as it still works on Node 14 (which ES2019 obviously will). But I would guess that with AWS deprecating Node 12 and encouraging people to use ES2020 features available in Node 14, you might be tempted to by default use tsconfig.json files with ES2020 level, and this will fail with serverless-webpack.

In my case, it was both my module containing the lambda and an external library which failed, so I have to go change the tsconfig.json also in the external library. Had I not owned that library as well, I might have been in greater trouble. So, assuming developers might start publishing libraries where the dist uses ES2020 features, this will be a severe problem for serverless-webpack?

Additional Data

herebebogans commented 3 years ago

I had similar issue with webpack 4 - switching to webpack 5 solved it.

j0k3r commented 3 years ago

@henhal can you try switching to webpack 5?

henhal commented 3 years ago

@j0k3r I tried to install webpack 5 in my own module using serverless-bundle, but it still used webpack 4. The serverless-webpack module properly uses peerDependencies for webpack, but serverless-bundle does not - it requires webpack ^4. Not sure if there's any way to try using webpack 5 without forking serverless-bundle, I'll try that.