serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack
MIT License
1.72k stars 414 forks source link

Missing entry point(s) when using serverless-google-cloudfunctions #368

Open sohailalam2 opened 6 years ago

sohailalam2 commented 6 years ago

Bug Report

Description

Missing entry point(s) when using serverless-google-cloudfunctions

For bug reports:

service: sls-test

provider:
  name: google
  runtime: nodejs
  project: test-project
  credentials: ~/.gcloud/key.json

plugins:
  - serverless-webpack
  - serverless-google-cloudfunctions

custom:
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true

package:
  exclude:
    - node_modules/**
    - .gitignore
    - .git/**

functions:
  first:
    handler: http
    events:
      - http: path

webpack.config.js

const slsw = require('serverless-webpack');
const webpackNodeExternals = require('webpack-node-externals');

module.exports = {
    entry: slsw.lib.entries,
    target: 'node',
    devtool: 'source-map',
    externals: [webpackNodeExternals()],
    mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
    optimization: {
        minimize: false
    },
    performance: {
        hints: false
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                include: __dirname,
                exclude: /node_modules/
            }
        ]
    }
};
Serverless: Bundling with Webpack...

  Webpack Options Validation Error -----------------------

  Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
   object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
   -> The entry point(s) of the compilation.
   Details:
    * configuration.entry should not be empty.
      -> Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.
    * configuration.entry should be a string.
      -> An entry point without name. The string is resolved to a module which is loaded upon startup.
    * configuration.entry should be an array:
      [non-empty string]
    * configuration.entry should be an instance of function
      -> A Function returning an entry object, an entry string, an entry array or a promise to these things.

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

For feature proposals:

Similar or dependent issue(s):

Additional Data

 OS:                     linux
 Node Version:           9.3.0
 Serverless Version:     1.26.1
HyperBrain commented 6 years ago

Hi @sohailalam2 . Can you post your serverless.yml. I think it has something to do with your handler definitions of the functions that are used to create the entry points in the plugin.

sohailalam2 commented 6 years ago

Hey @HyperBrain ... its already added with the issue... please check the What was the config you used? section. Thanks Also, just FYI, I tried using the serverless generator serverless-google-cloudfunctions without the serverless-webpack and it does work.. the function was deployed successfully.

HyperBrain commented 6 years ago

@sohailalam2 Indeed - I missed that 😄

However maybe we should ask someone who uses Google (I only use AWS right now) to get a fast solution for the problem. Imo it should be some configuration issue because others are using it successfully.

@gastonmorixe Can you help out here? I saw in #309 that you also use Google as provider.

@sohailalam2 Just comparing his sls.yml and yours, I see that he uses a switched plugin order. Can you also use tha same one, because within serverless the order is important?

sohailalam2 commented 6 years ago

@HyperBrain Thanks for the comment... I did tried changing the order and ended up with the same issue.

HyperBrain commented 6 years ago

@pmuens Do you have any advice when using the Google provider plugin together with serverless-webpack and can help out here?

joshughes commented 6 years ago

I changed entry: slsw.lib.entries to just index.js (where my function is)

And this error goes away.

it seems like the root cause is slsw.lib.entries is not finding the correct file in this case.

Anyway, works fine after you just point entry to the right thing.

CoreyCole commented 6 years ago

BTW I was getting this error because I'm a noob and I didn't read the documentation. For anyone else running into this, just running webpack throws this error, but running serverless webpack --out dist works and gives webpack the proper entries value.

sohailalam2 commented 6 years ago

@joshughes this is ok for a single entry point, however, for complex projects, we can easily have multiple entry points and then it would be a pain to maintain all of those manually. slsw.lib.entries must return and wire up the entries as expected. This happens without any issue with the AWS provider.

@HyperBrain any update on this?

HyperBrain commented 6 years ago

@sohailalam2 This seems to originate from different handler specifications when using AWS and Google. As I do not use Google at work nor for my private projects, can you post a sample of the function definitions or a sample repo (a bit more complex) where we can try to debug? In the original serverless.yml of the issue, it also seems that there is no "exported function" defintion in the handler defintion (http vs. http.handle). It might be, that this is the root of the issue.

If Google functions use a different semantics for the handler declarations, the plugin should interpret them differently than with AWS. That should solve the problem.

markmssd commented 6 years ago

I'm also having a lot of trouble getting it to work with Google Cloud Functions (https://github.com/serverless/serverless-google-cloudfunctions)... it does not seem to support package.individually: true. Did you guys end up with a solution? Thanks!

PabloRN commented 4 years ago

Just get sure within your serverless.yml your- ${file(functions/function.yml)} path is ok