2

Why is my one computer including dev dependencies when packaging a Serverless Framework project but my other computer is not?

When packaging and deploying my Serverless project targeted for AWS, I found that the zip package contained dev dependencies in the node_modules folder. This only happened on one of my two computers. When performing the same build steps on AWS CodeBuild, the package was also ok with not including dev dependencies.

package.json

{
  "name": "project-name",
  "version": "0.0.1",
  "description": "description",
  "main": "index.js",
  "dependencies": {
    "amazon-cognito-identity-js": "^3.0.10",
    "aws-sdk": "^2.488.0",
    "axios": "^0.18.0",
    "js-sha256": "^0.9.0",
    "jsonwebtoken": "^8.5.1",
    "jwk-to-pem": "^2.0.1",
    "node-fetch": "^2.3.0",
    "uuid": "^3.3.2",
    "lodash": "^4.17.11"
  },
  "devDependencies": {
    "chai": "^4.2.0",
    "eslint": "^5.16.0",
    "eslint-config-node": "^4.0.0",
    "mocha": "^6.0.2",
    "serverless": "^1.69.0",
    "sinon": "^7.4.2",
    "sinon-test": "^2.4.0"
  },
  "scripts": {
    "test": "mocha ./test --recursive"
  },
  "repository": {
    "type": "git",
    "url": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/reponame"
  },
  "author": "",
  "license": "ISC"
}

serverless.yml file that tried packaging but included dev dependencies.

service: service-name

# pinning serverless version for this project so all contributors are using the same version for consisten results
frameworkVersion: ">=1.60.0"
provider:
  name: aws
  runtime: nodejs10.x
  stage: ${opt:stage, 'dev'} # default stage to use, unless overridden on command lin
  region: us-east-1

functions:
  create:
    handler: create/index.create
    events:
      - http:
          path: /{id}
          method: post
          cors: true

Both computers were windows 10 with the following Node versions - npm version 6.4.1 - node version 10.15.3

I tried completely uninstalling Node.js from my Windows computer following Uninstall Node.js and reinstalling Node.js but it did not work.

I tried searching for other node_modules folders on my computer and removing them but the project still included the dev dependencies.

I tried building a simple Serverless project but it also included the dev dependencies.

dcstingray
  • 21
  • 2

1 Answers1

0

The only solution I found to solve my problem was to perform a reset of windows (keeping user data, only removing application data). There must have been something in the applications, AppData, etc. that caused this issue.

After resetting windows 10 where user data was kept and only application data was removed, installing Node.js (same version as before) and installing Serverless (same version as before), the dev dependencies were no longer included in the node_modules section of the package that was generated.

dcstingray
  • 21
  • 2
  • This issue came up again recently again. I had moved to NodeJs (14.18.3) and npm (6.14.15) since the last time it occurred and recently (several months of working perfectly with removing dev dependencies) it started happening again. The node version does not seem to be the issue. If anyone has any suggestions other than resetting windows, that would be helpful as resetting windows is a horrible solutions. – dcstingray Jul 23 '22 at 03:02