You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Create a Lambda function that uses the pg module
Deploy it with pg 8.15.0 or 8.15.1 in a Lambda Layer
Invoke the Lambda function
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!
The text was updated successfully, but these errors were encountered:
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. [email protected] should work. Please feel free to report any other issues you find!
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
Context
import { Client } from "pg";
Environment Details
Steps to Reproduce
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!
The text was updated successfully, but these errors were encountered: