serverless-optimizer-plugin icon indicating copy to clipboard operation
serverless-optimizer-plugin copied to clipboard

Optimizer crashes on ES2015-compliant code.

Open cdichiara opened this issue 9 years ago • 7 comments

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.

cdichiara avatar Apr 21 '16 02:04 cdichiara

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.

aendra-rininsland avatar Apr 29 '16 18:04 aendra-rininsland

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?

cdichiara avatar Apr 30 '16 13:04 cdichiara

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.

vmadman avatar May 06 '16 23:05 vmadman

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.

n8sabes avatar May 13 '16 08:05 n8sabes

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.

Howard3 avatar Jun 17 '16 06:06 Howard3

Thanks @Howard3, this was really helpful as a stopgap solution...

cdichiara avatar Jul 05 '16 18:07 cdichiara

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

AdrienLemaire avatar Jul 22 '16 03:07 AdrienLemaire