floydspace / serverless-esbuild

💨 A Serverless framework plugin to bundle JavaScript and TypeScript with extremely fast esbuild
MIT License
445 stars 138 forks source link

Bug - Please install pg package manually after the deployment #467

Open akshay-scalex opened 1 year ago

akshay-scalex commented 1 year ago

Describe the bug I am using postgresql as database and sequelize as ORM. When I run the code locally it works fine. But when deployed, it throws an error - Please install pg package manually.

Expected behavior When deployed the query should return the data from postgresql database.

Screenshots or Logs Screenshot 2023-05-23 at 5 16 15 PM

Versions (please complete the following information):

Additional context tsconfig.json file

{
  "extends": "./tsconfig.paths.json",
  "compilerOptions": {
    "lib": ["ESNext"],
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "removeComments": true,
    "sourceMap": true,
    "target": "ES2020",
    "outDir": "lib"
  },
  "include": ["src/**/*.ts", "serverless.ts"],
  "exclude": [
    ".serverless/**/*",
    ".webpack/**/*",
    "_warmup/**/*",
    ".vscode/**/*"
  ],
  "ts-node": {
    "require": ["tsconfig-paths/register"]
  }
}

serverless.ts file

import type { AWS } from "@serverless/typescript";

import helloWorld from "@functions/hello_world";

const serverlessConfiguration: AWS = {
    service: "hello-world-service",
    frameworkVersion: "3",
    plugins: [
        "serverless-esbuild",
        "serverless-offline",
        "serverless-dotenv-plugin",
    ],
    useDotenv: true,
    provider: {
        name: "aws",
        runtime: "nodejs14.x",
        timeout: 10,
        apiGateway: {
            minimumCompressionSize: 1024,
            shouldStartNameWithService: true,
        },
        environment: {
            AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1",
            NODE_OPTIONS: "--enable-source-maps --stack-trace-limit=1000",
            DATABASE_NAME: process.env.DATABASE_NAME,
            DATABASE_USERNAME: process.env.DATABASE_USERNAME,
            DATABASE_PASSWORD: process.env.DATABASE_PASSWORD,
            DATABASE_HOST: process.env.DATABASE_HOST,
            DATABASE_PORT: process.env.DATABASE_PORT,
            DATABASE_DIALECT: process.env.DATABASE_DIALECT,
            REGION: process.env.REGION,
        },
    },
    // import the function via paths
    functions: {
        helloWorld
    },
    package: { individually: true },
    custom: {
        esbuild: {
            bundle: true,
            minify: false,
            sourcemap: true,
            exclude: ["aws-sdk"],
            target: "node14",
            define: { "require.resolve": undefined },
            platform: "node",
            concurrency: 10,
            external: ["pg"],
        },
        dotenv: {
            path: `config`,
        },
    },
};

module.exports = serverlessConfiguration;
derekbar90 commented 1 year ago

I'm seeing similar issues. Started happening 12 hours ago.

floydspace commented 1 year ago

I'm seeing similar issues. Started happening 12 hours ago.

I'm not sure how it could be related to the latest release https://github.com/floydspace/serverless-esbuild/commit/49ad43e6cd3964e0ca04bbbac98f21935b40afd3

we have just changed the default build target from node12 to node16, could you explicitly try changing it? so we can understand if it caused the issue.