serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aws-sdk: warning on deployment

shavo007 opened this issue · comments

This is a Bug Report

Description

Updated webpack serverless and now get warning when deploying

Serverless: WARNING: Runtime dependency 'aws-sdk' found in devDependencies. You should use forceExclude to explicitly exclude it.

Config:

const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const Dotenv = require('dotenv-webpack');

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  // Generate sourcemaps for proper error messages
  devtool: 'source-map',
  // Since 'aws-sdk' is not compatible with webpack,
  // we exclude all node dependencies
  externals: [nodeExternals()],
  mode: slsw.lib.webpack.isLocal
    ? 'development'
    : 'production',
  optimization: {
    // We no not want to minimize our code.
    minimize: false
  },
  performance: {
    // Turn off size warnings for entry points
    hints: false
  },
  plugins: [new Dotenv()],
  // Run babel on all .js files and skip those in node_modules
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  }
};

Similar or dependent issue(s):

Additional Data

  • Serverless-Webpack Version you're using: 5.1.5
  • Webpack version you're using: 4.8.3
  • Serverless Framework Version you're using: 1.27.2
  • Operating System: linux
  • Stack Trace (if available):

Hi @shavo007 , thanks for the report 👍 .

This warning is expected, because I improved the dependency detection to be able to find common issues where dependencies are set in devDependencies instead of dependencies (I treated this missing behavior as a bug, because it could lead to defunctional deployments). These issues are very hard to track down, because previously they only led to crashes when deployed.
However, for the aws-sdk this is expected, because it normally is in devDependencies although it is referenced at runtime. That's why it leads to a warning and not an error as other dependencies would do. Functional, there is no difference on deployment as with the previous serverless-webpack versions, only that a warning is printed.

To get rid of the warning and have a correct project setup you should set the aws-sdk as forcefully excluded. This explicitly states that it is not deployed intentionally (as the serverless.yml is declarative, this is then more correct than silently excluding it). So, just add:

custom:
  webpack:
    includeModules:
      forceExclude:
        - aws-sdk

in your serverless.yml and the warning will be gone and it expresses, what is happening and what is intended.

I'll change the issue subject, so that others who recognize the warning can lookup and find it more easily.

hi @HyperBrain thanks for the response.

Issue is that it is correctly defined as a dev dependency (aws lambda includes aws-sdk in container).

see https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html

That is why i do not have it as a dependency.

When i see a warning in my CI server i assume there is a problem.

What you think?

@shavo007 As I wrote, there is no problem and you defined it correctly in devDependencies 😃 . The warning is only a hint that aws-sdk should be set as forceExclude to let the system know that you intended to have it that way (which is fully normal for it).

The only thing you should do is, to define the forceExclude: ... aws-sdk to explicitly state that you are aware of this to have the configuration reflect exactly what is set up in your service.

I added some docs in #395 to explain the behavior (thanks to @arabold for the idea).
However, could someone please check the wording and placement of the paragraphs, if it is ok how I did it?

tbh @HyperBrain im just not a big fan of this change!

i shoudnt have to declaratively exclude aws-sdk to resolve the warning. When in fact I am doing the right thing and defining it as a dev dependency.

Why have this warning in the first place? Why not have a whitelist and exclude aws-sdk?

Thoughts?

@shavo007 What we could do is, to restrict the warning to only show up with --verbose and change it to an informational message then, like INFO: devDependency aws-sdk has been excluded automatically. This could be a bit clearer and as you said, actually it is no issue and the standard behavior. How does that sound?

@HyperBrain info sounds good. but thats just my opinion!!