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

Serverless re running the npm install during deployment when using node-externals #84

Open
programoholic opened this issue Sep 21, 2020 · 0 comments

Comments

@programoholic
Copy link

I am working on a node application using serverless architecture. We are using serverless-webpack plugin to build the application. Here is the webpack.config.js :

module.exports = {
  mode: isLocal ? 'development' : 'production',
  entry: slsw.lib.entries,
  externals: [nodeExternals()],
  devtool: 'inline-cheap-module-source-map',
  resolve: {
    extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
  },
  output: {
    libraryTarget: 'commonjs2',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  },
  optimization: {
    minimize: true,
    minimizer: [new TerserPlugin()],
  },
  target: 'node',
  module: {
    rules: [{
        test: /\.ts$/,
        exclude: /node_modules/,
        loader: 'ts-loader',
        options: {
          // disable type checker - we will use it in fork plugin
          transpileOnly: true
        }
      },
      {
        test: /\.(graphql|gql)$/,
        exclude: /node_modules/,
        loader: 'graphql-tag/loader',
      }
    ]
  },
  // plugins: [new ForkTsCheckerWebpackPlugin()]
};

and serverless.yml file. :

service: app
provider:
  name: aws
  region: ${env:AWS_REGION}
  stage: ${env:STAGE}
  logRetentionInDays: 90
  role: ${env:ROLE}
  versionFunctions: false
  runtime: nodejs12.x

package:
  individually: true

plugins:
- serverless-webpack
- serverless-offline

custom:
  webpack:
    webpackConfig: './webpack.config.js'
    packager: 'npm'
    includeModules: true

functions:
  ######## GraphQl ###########
  graphql:
    role: ${env:ROLE}
    runtime: nodejs12.x
    timeout: 30
    handler: aws/lambda/common/api/graphql.graphqlHandler
 
    events:
      - http:
          path: graphql
          method: post

      - http:
          path: graphql
          method: get

When I am running sls deploy --config serverless.yml to deploy the application , everything is working and the lambda is getting deployed successfully. Only thing is , during the process of deployment , it is using the package-lock.json and installing the used packages again :

Serverless: Package lock found - Using locked versions

Serverless: Packing external modules:  graphql-compose@^7.19.3, linewrap@^0.2.1, d64@^1.0.0, graphql-scalars@^1.2.6, graphql-tools@^6.0.12

Serverless: Packaging service...

My question is how to stop rerunning the npm install again during deployment instead it should use the existing node_moudles while packing the external modules. Can anybody help me on this. ?

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

1 participant