Skip to content
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

invoke doesn't work if the file isn't in the project root (for multiple entries) #66

Closed
brunobelotti opened this issue Dec 5, 2016 · 8 comments

Comments

@brunobelotti
Copy link

I was having problems invoking my functions after using the plugin, so I took further steps to better isolate the problem.
I cloned the repository and tried the "multiple-entries" example, everything works fine.
I then moved one of the functions inside a folder "functions", and updated serverless.yaml accordingly:

  first:
    handler: functions/first.hello

Same for webpack.config.js:

  entry: {
    first: './functions/first.js',
    second: './second.js'
  },

After deployment, if I sls invoke local -f first everything works, if I sls invoke -f first I get an error:

{
    "errorMessage": "Cannot find module '/var/task/functions/first'",
    "errorType": "Error",
    "stackTrace": [
        "Module.require (module.js:353:17)",
        "require (internal/module.js:12:17)"
    ]
}

With the second function, in the project root, everything works as expected.
Also, if I disable the plugin, everything work as expected.
Am I missing something or is there a bug?

Thank you! :)

@andymac4182
Copy link

You can do something like

  entry: {
    '/functions/first': './functions/first.js',
    second: './second.js'
  },

This is what we are doing at the moment.

@brunobelotti
Copy link
Author

brunobelotti commented Dec 6, 2016

Thanks @andymac4182, that worked like a charm. 👍

Two questions now:

  1. Why is this necessary (and, purely out of curiosity, how did you come up with this solution)?
  2. Should we consider this as a bug or is it the intended/only-possible behaviour (hence, I'll close the issue)?

Thanks again!

@thenikso
Copy link
Contributor

neat. I'm seeing various issues like this one that would greatly help if added somehow in the readme and/or examples. I believe we are getting close to a definitive workflow for this plugin.

In this case I think @andymac4182 solution is the way to go as resolving handlers as if they were folders to then map the result inside a bundled js would become quite cumbersome without a huge gain imo. thoughts?

@kirkstrobeck
Copy link

Specifying output is essential to this solution.

@HyperBrain
Copy link
Member

serverless invoke local will be fully supported in the upcoming v3.
Additionally the output and handler detection has been automated in version 2.2.0.
You can now just use:

// webpack.conf.js
const slsw = require('serverless-webpack');
module.exports = {
  ...
  entry: slsw.lib.entries,
  ...
  output: {
    ...
    filename: '[name].js',
    ...
  }
};

You can test sls invoke local and the new sls invoke local --watch support already with the v3.0.0 or v3.0.0-individual-packaging branches.

@HyperBrain
Copy link
Member

You can try the v3 release candidate, see #187

@HyperBrain
Copy link
Member

@brunobelotti @andymac4182 Did you check if the V3 RC solves your problems? I'll tend to close this task, as there have not been any responses recently.

@HyperBrain
Copy link
Member

Closing the issue - if the issue still persists, feel free to re-open it or create a new one for the most current version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants