-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES2015 Deployed Code Crashes -- Optimizer not observing strict mode #19
Comments
@n8sabes try adding babel-plugin-transform-strict-mode to the transforms array in the same manner as babelify (see below for example and add opts if needed). That's what I did with my coffeeify transform and it worked fine. Be sure to install/save the package in the root node_modules of your sls project. Hope that helps.
|
Thanks @staceymoore. I added the package to the project root and included the plugin to the transforms. Still no love, getting the following error with --debug option and not finding a good solution example (some gulp references). Did you configure or install anything else?
|
Browserify doesn't seem to care about these kind of syntactic errors, at least it doesn't fail during the bundling process. However, it DOES include the "use strict" statement in the bundled package. Some things you could do:
|
Hey @joostfarla -- Thanks for the conversation on the problem, and for your time looking at it. Option 1: Options 2: Your new JSHint plugin is a MUCH better idea to prevent bad deployments. Excited to try it and will let you know the outcome! @staceymoore, thanks to you for your help on this topic as well. |
The serverless-optimizer-plugin does not appear to be observing
'use strict’;
Thus, not defining a variable withvar
is ignored and when the code is deployed, it crashes in the Lambda environment.To reproduce this issue:
1). Setup fresh project with a single component and function.
Make sure
'use strict;'
is at the top of the function file.Add the following line to the function handler
sls function run component/function -s dev
Check CloudWatch for Crash
ReferenceError: foo is not defined
.*var
ahead of the variable:sls function run [path]
Works fine now.
Serverless deployment process should catch this error (due to strict mode) and fail. Not catching these errors results in unstable code being deployed that is out of spec.
If possible, adding babel-plugin-transform-strict-mode might help. How can this plugin be added to the optimizer json? It really shouldn't be required when strict is declared at the top of the file, but it would be nice to know how to include plugins for babel.
The text was updated successfully, but these errors were encountered: