1

When I build my nestjs application with nx to ship it to elasticbeanstalk via pulumi, it does not include follwing packages in generated package.json

  • tslib
  • class-transformer
  • @nestjs/platform-socket.io

Is there a way to bundle them correctly or include in package.json?

Here is my project.json

{
  "name": "api",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/api/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nrwl/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "options": {
        "target": "node",
        "compiler": "tsc",
        "outputPath": "dist/apps/api",
        "main": "apps/api/src/main.ts",
        "tsConfig": "apps/api/tsconfig.app.json",
        "assets": ["apps/api/src/assets"],
        "tsPlugins": [
          {
            "name": "@nestjs/swagger/plugin",
            "options": {
              "dtoFileNameSuffix": [".entity.ts", ".dto.ts"],
              "controllerFileNameSuffix": [".controller.ts"],
              "classValidatorShim": true,
              "dtoKeyOfComment": "description",
              "controllerKeyOfComment": "description",
              "introspectComments": true
            }
          }
        ],
        "generatePackageJson": true
      },
      "configurations": {
        "production": {
          "optimization": true,
          "extractLicenses": true,
          "inspect": false,
          "fileReplacements": [
            {
              "replace": "apps/api/src/environments/environment.ts",
              "with": "apps/api/src/environments/environment.prod.ts"
            }
          ]
        }
      }
    },
    "zip": {
      "executor": "nx:run-commands",
      "options": {
        "commands": [
          "echo 'web: node main.js' > Procfile",
          "cp -r ../../../libs/shared/prisma .",
          "cp -r ../../../apps/api/.platform .",
          "json -I -f package.json -e 'this.dependencies.tslib=\"^2.0.0\"' && zip -r ../api.zip ."
        ],
        "cwd": "dist/apps/api"
      }
    },

    "serve": {
      "executor": "@nrwl/js:node",
      "options": {
        "buildTarget": "api:build"
      },
      "configurations": {
        "production": {
          "buildTarget": "api:build:production"
        }
      }
    },
    "lint": {
      "executor": "@nrwl/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["apps/api/**/*.ts"]
      }
    },
    "test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "apps/api/jest.config.ts",
        "passWithNoTests": true
      }
    },
    "deploy": {
      "executor": "nx:run-commands",
      "options": {
        "commands": ["nx run api-infrastructure:up"]
      }
    }
  },
  "tags": []
}

Here is my tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "commonjs",
    "types": ["node", "express", "multer"],
    "emitDecoratorMetadata": true,
    "target": "es2015"
  },
  "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
  "include": ["**/*.ts", "../../libs/shared/**/*.ts"]
}

And here is my tsconfig.base.json (the one in the root)


{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2017", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@epicode/aws-components": ["libs/aws-components/src/index.ts"],
      "@epicode/shared": ["libs/shared/src/index.ts"],
      "@epicode/shared-ui": ["libs/shared-ui/src/index.ts"],
      "@epicode/types": ["libs/types/src/index.ts"]
    }
  },
  "exclude": ["node_modules", "tmp"]
}

I was expecting all dependencies would be bundled if I don't use "generatePackageJson": true

Or If I use it they would show up in package.json.

My current workaround is adding them into main.ts file

import 'class-transformer';
import '@nestjs/platform-socket.io';

and to package.json manually before zipping it and deploying it.

Ubeyt Demir
  • 332
  • 3
  • 10

0 Answers0