【问题标题】:Serverless Framework not excluding dev dependencies when packaging打包时无服务器框架不排除开发依赖项
【发布时间】:2020-08-20 07:05:15
【问题描述】:

为什么我的一台计算机在打包无服务器框架项目时包含开发依赖项,而我的另一台计算机却没有?

在打包和部署面向 AWS 的无服务器项目时,我发现 zip 包在 node_modules 文件夹中包含开发依赖项。这仅发生在我的两台计算机中的一台上。在 AWS CodeBuild 上执行相同的构建步骤时,包也可以,不包括开发依赖项。

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 文件。

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

两台计算机都是 Windows 10,具有以下节点版本 - npm 版本 6.4.1 - 节点版本 10.15.3

我尝试在 Uninstall Node.js 之后从我的 Windows 计算机上完全卸载 Node.js 并重新安装 Node.js,但没有成功。

我尝试在我的计算机上搜索其他 node_modules 文件夹并删除它们,但该项目仍然包含开发依赖项。

我尝试构建一个简单的无服务器项目,但它也包含开发依赖项。

【问题讨论】:

    标签: node.js dependencies packaging serverless


    【解决方案1】:

    我发现解决问题的唯一方法是重置窗口(保留用户数据,仅删除应用程序数据)。应用程序、AppData 等中一定有某些东西导致了这个问题。

    在重置保留用户数据且仅删除应用程序数据的 Windows 10、安装 Node.js(与以前相同的版本)和安装 Serverless(与以前相同的版本)后,dev 依赖项不再包含在 node_modules 部分中生成的包。

    【讨论】:

      猜你喜欢
      • 2021-08-23
      • 2018-06-02
      • 2018-05-12
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      • 2021-02-27
      • 2021-01-23
      • 2018-07-07
      相关资源
      最近更新 更多