question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serverless package does not include all modules when a package.json file is provided

See original GitHub issue

This is a (Bug Report)

Description

When deploying multiple versions of a service or just versions of the function within the service, but sometimes some modules are not included in the package in presence of a package.json file

  • What went wrong? When using sls deploy or sls deploy -f functionName or sls package the service.zip doest not include all my node_modules, when I checked the package I figured out that some modules were missing My tree:
lamba
  dir
  dir
  index.js
  package.json
  serverless.yml
  node_modules

My package.json file was something like this:

{
  "name": "lambda",
  "version": "1.0.0",
  "description": "lambda",
  "main": "index.js",
  "dependencies": {
    "handlebars": "^4.0.10",
    "html-pdf": "^2.1.0",
    "mathfinjs": "^1.0.2",
    "moment": "^2.18.1",
    "numeral": "^2.0.6",
    "path": "^0.12.7",
    "pdfkit": "^0.8.3",
    "pg": "^6.4.0",
    "request-promise": "^4.2.1"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "RAZ",
  "license": "ISC"
}
  • What did you expect should have happened?

That every time that I deploy a service/function the package be the same but request-promise and pg were missing

  • What was the config you used?
service: service

frameworkVersion: ">=1.8.0 <2.0.0"

provider:
  name: aws
  runtime: nodejs6.10
  region: us-west-2
  versionFunctions: false

functions:
  function:
    handler: index.handler
    description: description
    memorySize: 1024
    timeout: 30
    role: arn-role
    tags:
      Department: IT
      Name: name
      Team: team
      TeamMember: TeamMember
    environment:
      var: value
      var: value
      var: value
      var: value
      var: value
    
  • What stacktrace or error message from your provider did you see?
{
  "errorMessage": "Cannot find module 'request-promise'",
  "errorType": "Error",
  "stackTrace": [
    "Module.require (module.js:497:17)",
    "require (internal/module.js:20:19)",
    "Object.<anonymous> (/var/task/index.js:14:23)",
    "Module._compile (module.js:570:32)",
    "Object.Module._extensions..js (module.js:579:10)",
    "Module.load (module.js:487:32)",
    "tryModuleLoad (module.js:446:12)",
    "Function.Module._load (module.js:438:3)"
  ]
}
Unable to import module 'index': Error
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/var/task/index.js:14:23)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

Similar or dependent issues:

Additional Data

Even using include: file was useless

The solution for me was to rename/remove package.json file

  • Serverless Framework Version you’re using: 1.16.1
  • Operating System: macOS Sierra 10.12.5

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

12reactions
pmuenscommented, Jul 7, 2017

Hey @xmissio thanks for opening! 👍

This could be related to https://github.com/serverless/serverless/pull/3889.

Could you try to re-deploy while opting out of the dev dependency exclusion functionality?

You can opt-out via:

package:
  excludeDevDependencies: false
11reactions
celicoocommented, Feb 26, 2018

I’m experiencing the same issue in version 1.26.0. Any one else?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serverless not including my node_modules - Stack Overflow
When debugging serverless 's packaging process, use sls package (or sls deploy --noDeploy (for old versions). You'll get a .serverless ...
Read more >
Package excludes do not seem to work - Serverless Forums
I'm having the same problem. The way excludes/includes and individual packaging work don't seem to line up with the documentation. I'm currently ...
Read more >
Serverless Webpack - Serverless Plugin Directory
However, you don't want to include all modules in some cases such as selectively import ... By default, the plugin will use the...
Read more >
Specifying dependencies in Node.js - Cloud Functions
In this example, a dependency is listed in the package.json file: ... You can also include local Node.js modules as part of your...
Read more >
package-lock.json - npm Docs
No package folders exist in the node_modules hierarchy that are not listed in the lockfile. The modified time of the file is at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found