Optimizer crashes on ES2015-compliant code.
So, getting this error:
JS_Parse_Error {
message: 'Unexpected token: name (tempPass)',
filename: 'C:\\Users\\...\\_meta\\_tmp\\clientApi@1461203961098\\optimized\\clientApi\\_serverless_handler.js',
The code is:
let tempPass = request.password;
A similar issue with:
var cognitoParams = {
IdentityPoolId: process.env.cognitoIdentityPool,
Logins: {
[process.env.cognitoDeveloperName]: cognitoKey
}
};
Result is:
Serverless: ------------------------
Serverless: Failed to deploy the following functions in "carmine" to the following regions:
Serverless: us-east-1 ------------------------
Serverless: clientApi: Unexpected token: name (process)
C:\Users\...\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:61
fn = function () { throw arg; };
This is serverless-optimizer-plugin v2.5.1. Code is running fine on Lambda when I remove the optimizer plugin.
I have the same thing. It's an arrow function that's causing it. It seems Babelify isn't being run on stuff before uglify.
Yeah, & now I wonder ... does Babel always convert back to pre-ES2015? Because I'm using the Node 4.3 executable on AWS right now ... perhaps Babel has less to do now?
Yes, same issue here. I also think that Babel is no longer needed and, thus, am not using it.. but then hit errors on my ES6 compatible statements (e.g. "let", but wondering, now, if I am missing a fundamental and should start saying "ES2015" from now on).
The one thing I have managed to figure out is that Uglify is the culprit here, as it is the one lacking ES6 support, but I think @aendrew eluded to that already.
See: serverless/serverless#1016 See: serverless-runtime-babel #16
I believe es2015 unnecessarily transpiles a lot of ES6 logic that is natively supported in the Node 4.3.x Lambda (V8) Execution Environment. For deployed (code size and speed), es20515-node4 makes the most sense for ES6-based solutions and needs to be fixed.
If you're looking at using optimizer simply to make fully es6 run on lambda, just set "minify": false in the "optimize" config. This should be fixed though.
Thanks @Howard3, this was really helpful as a stopgap solution...
Thank you @Howard3 , I could never use optimizer due to these kind of errors, and I can now reduce my zip files from 3.3M to 540K even without minify