serverless / serverless-optimizer-plugin

Serverless Optimizer Plugin: Optimizers for reducing Lambda file sizes and improving their performance -
http://www.serverless.com
102 stars 30 forks source link

serverless v0.5 and optimizer #23

Open srg-clearlaunch opened 8 years ago

srg-clearlaunch commented 8 years ago

I'm testing the v0.5 branch for the serverless guys and looks like there is a problem with the optimizer plugin and the new code. I'm able to deploy without issue if serverless-optimizer-plugin is not included in the s-project.json plugins, however once included I get the following:

Serverless: Deploying functions in "development" to the following regions: us-east-1  
Serverless: ------------------------  
Serverless: Failed to deploy the following functions in "development" to the following regions:  
Serverless: us-east-1 ------------------------  
Serverless:   listaccounts: Cannot read property 'getFunctions' of undefined  
/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:49
        fn = function () { throw arg; };
                           ^

ServerlessError: Lambda Deployment Failed.
    at new ServerlessError (/usr/local/lib/node_modules/serverless/lib/Error.js:17:11)
    at FunctionDeploy.<anonymous> (/usr/local/lib/node_modules/serverless/lib/actions/FunctionDeploy.js:137:19)
    at next (/usr/local/lib/node_modules/serverless/node_modules/rimraf/rimraf.js:74:7)
    at FSReqWrap.CB [as oncomplete] (/usr/local/lib/node_modules/serverless/node_modules/rimraf/rimraf.js:110:9)
From previous event:
    at FunctionDeploy.functionDeploy (/usr/local/lib/node_modules/serverless/lib/actions/FunctionDeploy.js:116:10)
From previous event:
    at /usr/local/lib/node_modules/serverless/lib/Serverless.js:188:29
    at Array.reduce (native)
    at /usr/local/lib/node_modules/serverless/lib/Serverless.js:187:30
From previous event:
    at Serverless._execute (/usr/local/lib/node_modules/serverless/lib/Serverless.js:185:10)
    at Serverless.actions.(anonymous function) (/usr/local/lib/node_modules/serverless/lib/Serverless.js:407:20)
    at Serverless.command (/usr/local/lib/node_modules/serverless/lib/Serverless.js:376:38)
    at /usr/local/lib/node_modules/serverless/bin/serverless:19:16
    at processImmediate [as _immediateCallback] (timers.js:383:17)
From previous event:
    at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless:18:4)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)
    at node.js:963:3
austencollins commented 8 years ago

Thanks, still fixing this. Almost done :)

ajagnanan commented 8 years ago

Should be good with #27 :smile:

purplecones commented 8 years ago

I get this error just by adding "serverless-optimizer-plugin" to the plugins array in s-project.json.

/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:49
        fn = function () { throw arg; };
                           ^

TypeError: Class extends value #<Serverless> is not a function or null
    at module.exports.ServerlessPlugin.browserify._this.config.requires.map._this.config.plugins.map._this.config.transforms.map._this.config.exclude.forEach._this.config.ignore.forEach._generateIncludePaths (xxxxxx/node_modules/serverless-optimizer-plugin/index.js:21:37)
    at Serverless._loadPlugins (/usr/local/lib/node_modules/serverless/lib/Serverless.js:286:25)
    at Serverless.loadProjectPlugins (/usr/local/lib/node_modules/serverless/lib/Serverless.js:240:10)
    at /usr/local/lib/node_modules/serverless/lib/Serverless.js:77:41
From previous event:
    at Serverless.init (/usr/local/lib/node_modules/serverless/lib/Serverless.js:73:25)
    at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless:17:12)
    at Module._compile (module.js:399:26)
    at Object.Module._extensions..js (module.js:406:10)
    at Module.load (module.js:345:32)
    at Function.Module._load (module.js:302:12)
    at Function.Module.runMain (module.js:431:10)
    at startup (node.js:141:18)
    at node.js:977:3

and just running sls

martinmicunda commented 8 years ago

I am getting exactly same error like @purplecones (serverless v0.5.0)

ajagnanan commented 8 years ago

You should install latest master, install it by adding this to package.json

"serverless-optimizer-plugin": "https://github.com/serverless/serverless-optimizer-plugin.git"
martinmicunda commented 8 years ago

thanks @ajagnanan

patoncrispy commented 8 years ago

Using babelify and trying to run a function, I get the following error:

class ServerlessOptimizer extends S.classes.Plugin {
                                            ^
TypeError: Cannot read property 'Plugin' of undefined
 at module.exports.S.classes.Plugin.browserify._this.config.requires.map._this.config.plugins.map._this.config.transforms.map._this.config.exclude.forEach (/Users/CP/Development/project/node_modules/serverless-optimizer-plugin/index.js:20:46)

My s-project.json has this defined:

"custom": {
    "serverless-offline": {
      "babelOptions": {
        "presets": ["es2015"]
      }
    },
    "optimize": {
      "exclude": ["aws-sdk"],
      "transforms": [
        {
          "name": "babelify",
          "opts": {
            "presets": [
              "es2015"
            ]
          }
        }
      ]
    }
  },
  "plugins": [
    "serverless-optimizer-plugin",
    "serverless-offline"
  ]

My dependencies are:

"dependencies": {
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-stage-0": "^6.5.0",
    "babelify": "^7.2.0",
    "serverless-offline": "^2.2.9",
    "serverless-optimizer-plugin": "^2.4.0"
  }

Any ideas why I would be getting this error?

martinmicunda commented 8 years ago

@patoncrispy you need to specify custom settings in s-function.json since serverless 0.5.0.. see issue #30

patoncrispy commented 8 years ago

So should I not have anything in my s-project.json, @martinmicunda? The docs suggest the following format:

{
  "name": "projectName",
  "custom": {}, // For plugin authors to add any properties that they need
  "plugins": [] // List of plugins used by this project
}
martinmicunda commented 8 years ago

you only move optimize config to s-function.json and everything else stay in s-project.json

s-function.json

  "custom": {
    "excludePatterns": [
      "node_modules"
    ],
    "optimize": {
      "exclude": [
        "aws-sdk"
      ],
      "transforms": [
        {
          "name": "babelify"
        }
      ],
      "minify": true
    }
  },