Skip to content

Lambda function fails after pg 8.15.0/8.15.1 update due to exports field change #3429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
742617000027 opened this issue Apr 23, 2025 · 2 comments

Comments

@742617000027
Copy link

Issue Description

After the update to pg 8.15.0/8.15.1, Lambda functions that use the pg module are failing with a Module not found error. This appears to be related to the new ESM support and changes to the exports field in package.json.

Error Message

{
    "errorType": "Error",
    "errorMessage": "Package subpath './lib/index.js' is not defined by \"exports\" in /opt/nodejs/node_modules/pg/package.json",
    "code": "ERR_PACKAGE_PATH_NOT_EXPORTED",
    "stack": [
        "Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/index.js' is not defined by \"exports\" in /opt/nodejs/node_modules/pg/package.json",
        "    at exportsNotFound (node:internal/modules/esm/resolve:320:10)",
        "    at packageExportsResolve (node:internal/modules/esm/resolve:667:9)",
        "    at resolveExports (node:internal/modules/cjs/loader:639:36)",
        "    at Function._findPath (node:internal/modules/cjs/loader:728:31)",
        "    at Function._resolveFilename (node:internal/modules/cjs/loader:1211:27)",
        "    at Function._load (node:internal/modules/cjs/loader:1055:27)",
        "    at TracingChannel.traceSync (node:diagnostics_channel:322:14)",
        "    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)",
        "    at Module.require (node:internal/modules/cjs/loader:1311:12)",
        "    at require (node:internal/modules/helpers:136:16)"
    ]
}

Context

  • This issue specifically affects AWS Lambda functions that use the pg module
  • The error occurs in a Lambda runtime environment
  • The error started occurring after the pg update to 8.15.0/8.15.1
  • The module is being imported correctly in our code with: import { Client } from "pg";

Environment Details

  • Node.js runtime: AWS Lambda Node.js 22x
  • pg version: 8.15.1
  • Using Lambda Layers to include node modules
  • Deployment using Pulumi infrastructure as code

Steps to Reproduce

  1. Create a Lambda function that uses the pg module
  2. Deploy it with pg 8.15.0 or 8.15.1 in a Lambda Layer
  3. Invoke the Lambda function
  4. Observe the error about package subpath not being defined by exports

Expected Behavior

The Lambda function should run successfully without any module resolution errors.

Actual Behavior

The Lambda execution fails with the module resolution error shown above.

Workaround

Pinning the pg module to version 8.14.1 resolves the issue, but we would prefer to use the latest version.

Additional Information

The error seems to be related to how the Lambda environment or some dependent module is trying to access internal paths like './lib/index.js' which are no longer available through the new exports field.

Question

Is there a recommended approach for Lambda environments to work with the new exports pattern?

Thank you for your assistance!

@brenoepics
Copy link
Contributor

This issue can be fixed with #3428

@brianc
Copy link
Owner

brianc commented Apr 23, 2025

Hey sorry about that. PR merged (thank you @brenoepics for the fix while I was sleeping!) and a new patch version of pg related modules released now. pg@8.15.2 should work. Please feel free to report any other issues you find!

@brianc brianc closed this as completed Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants