Issue description
Bug Description
The serverless package command fails with exit code 1 when running pnpm install --no-frozen-lockfile, but works perfectly when using the --debug flag. This happens both locally on macOS and in GitHub Actions CI/CD.
Environment Information
Local Environment:
- Framework Version: 4.22.0
- Platform: macOS Darwin 24.6.0 (ARM64_T6000 - Apple Silicon M1)
- Node Version: v20.11.0
- pnpm Version: 10.20.0
- npm Version: 10.2.3
CI Environment:
- Framework Version: 4.19.1
- Platform: Ubuntu 22.04
- Node Version: 20.x
- pnpm Version: 10
Current Behavior
❌ FAILS: Normal execution
$ serverless package
DOTENV: Loading environment variables from .env, .env.local:
- evs
Packaging "api" for stage "dev" (us-east-2)
✖ Error: `pnpm install --no-frozen-lockfile` Exited with code 1
at ChildProcess.<anonymous> (file:///Users/user/.serverless/releases/4.22.0/package/dist/sf-core.js:483:45752)
at ChildProcess.emit (node:events:530:35)
at ChildProcess.emit (node:domain:488:12)
at maybeClose (node:internal/child_process:1105:16)
at Socket.<anonymous> (node:internal/child_process:457:11)
at Socket.emit (node:events:518:28)
at Socket.emit (node:domain:488:12)
at Pipe.<anonymous> (node:net:337:12)```
### ✅ WORKS: With --debug flag
```bash
$ serverless package --debug
# Works successfully!
✅ WORKS: Manual pnpm install
$ pnpm install --no-frozen-lockfile
Lockfile is up to date, resolution step is skipped
Already up to date
. prepare$ npx husky install
│ husky - install command is DEPRECATED
└─ Done in 1.2s
Steps to Reproduce
- Have a Serverless v4 project with
pnpm-lock.yaml and the configuration below
- Run
serverless package → FAILS
- Run
serverless package --debug → WORKS
- Run
pnpm install --no-frozen-lockfile manually → WORKS
Project Configuration
serverless.yml
service: api
plugins:
- serverless-dotenv-plugin
- serverless-offline
- serverless-prune-plugin
provider:
name: aws
runtime: nodejs20.x
stage: ${opt:stage,'dev'}
region: us-east-2
timeout: 10
environment:
SERVICE_NAME: ${self:service}
logRetentionInDays: 30
architecture: arm64
memorySize: 1024
package:
individually: true
excludeDevDependencies: true
patterns:
- "!.git/**"
- "!**/*.test.*"
- "!**/__tests__/**"
- "!**/*.md"
- "!node_modules/**"
- "!.env*"
# Split into two separate APIs
resources:
Resources:
WebhooksApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: ${self:provider.stage}-api-webhooks
MainApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: ${self:provider.stage}-api
functions:
- ${file(./handlers/events.yml)}
# ESBuild configuration
build:
esbuild:
configFile: ./esbuild.config.js
buildConcurrency: 3
custom:
serverless-offline:
lambdaPort: 4002
reloadHandler: true
stage: ${opt:stage, self:provider.stage}
prune:
automatic: true # Automatically prune old versions after each deployment
number: 5 # Keep the 5 most recent versions
esbuild.config.js
module.exports = (serverless) => {
return {
bundle: true,
platform: "node",
target: "node20",
external: ["@aws-sdk/*", "@sentry/*", "mongoose", "lambda-log", "pdfkit"],
minify: true,
metafile: true,
buildConcurrency: 3,
treeShaking: true,
keepNames: true,
legalComments: "none",
}
}
package.json (slightly redacted)
{
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "chokidar 'handlers' 'src/**/*' 'serverless.yml' 'package.json' --ignore 'src/webhooks/**/*' -c 'pnpm kill-ports && sleep 1 && serverless offline --httpPort 4000 --noTimeout --reloadHandler' --initial --polling",
},
"keywords": [],
"dependencies": {
"@aws-sdk/client-s3": "^3.864.0",
"@sendgrid/mail": "^8.1.4",
"@sentry/aws-serverless": "^10.22.0",
"@sentry/profiling-node": "^10.22.0",
"axios": "^1.7.9",
"cli-progress": "^3.12.0",
"date-fns": "^4.1.0",
"date-fns-tz": "^3.2.0",
"ics": "^3.8.1",
"jsonwebtoken": "^9.0.2",
"jwt-decode": "^4.0.0",
"lambda-log": "^3.1.0",
"mailparser": "^3.7.2",
"mongoose": "8.0.1",
"mongoose-paginate-v2": "^1.7.4",
"pdfkit": "^0.16.0",
"qrcode": "^1.5.4",
"seatsio": "^85.10.0",
"short-uuid": "^5.2.0",
"stripe": "^17.5.0",
"uuid": "^11.0.5"
},
"devDependencies": {
"@eslint/js": "^9.22.0",
"@sentry/esbuild-plugin": "^4.6.0",
"@types/jest": "^30.0.0",
"chokidar-cli": "^3.0.0",
"esbuild-visualizer": "^0.7.0",
"eslint": "^9.22.0",
"globals": "^16.0.0",
"husky": "^9.1.7",
"jest": "^30.1.3",
"lambda-tester": "^4.0.1",
"mock-jwks": "1.0.10",
"mongodb-memory-server": "8.16.0",
"nock": "^13.5.6",
"serverless-domain-manager": "^8.0.0",
"serverless-dotenv-plugin": "^6.0.0",
"serverless-offline": "^14.4.0",
"serverless-prune-plugin": "^2.1.0",
"ts-jest": "^29.4.2",
"tsx": "^4.20.6",
"typescript": "^5.9.2"
}
}
Analysis & Observations
- The --debug flag changes the execution behavior - This suggests the issue is in how Serverless Framework spawns the pnpm child process in normal vs debug mode
- Manual pnpm install works perfectly - The issue is not with pnpm itself
- No actual error output from pnpm - The child process fails silently without stderr/stdout
- Happens on both macOS ARM64 and Ubuntu x64 - Not architecture-specific
- Using esbuild with custom config - May be related to the build pipeline, however I rolled back to the version before I made the esbuild changes and it still does not work.
Potential Root Causes
- Different stdio handling between debug and normal modes
- Race condition that debug mode avoids by being slower
- Issue with how the child process inherits the parent process environment
Attempted Solutions
- Verified pnpm is installed and in PATH
- Cleared pnpm cache with
pnpm store prune
- Deleted and reinstalled node_modules
- Confirmed Node version compatibility
Workarounds
- Use
serverless package --debug (works but verbose)
Expected Behavior
serverless package should work consistently regardless of the --debug flag when pnpm dependencies are already installed.
Additional Context
- Project uses husky git hooks (prepare script)
- Multiple serverless plugins are in use
- Using custom esbuild configuration
- Issue appeared recently without code changes
- Tried to run
serverless support --summary and got No previous command information was found even thought I had run the command before and followed instructions
Issue description
Bug Description
The
serverless packagecommand fails with exit code 1 when runningpnpm install --no-frozen-lockfile, but works perfectly when using the --debug flag. This happens both locally on macOS and in GitHub Actions CI/CD.Environment Information
Local Environment:
CI Environment:
Current Behavior
❌ FAILS: Normal execution
✅ WORKS: Manual pnpm install
Steps to Reproduce
pnpm-lock.yamland the configuration belowserverless package→ FAILSserverless package --debug→ WORKSpnpm install --no-frozen-lockfilemanually → WORKSProject Configuration
serverless.yml
esbuild.config.js
package.json (slightly redacted)
{ "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "chokidar 'handlers' 'src/**/*' 'serverless.yml' 'package.json' --ignore 'src/webhooks/**/*' -c 'pnpm kill-ports && sleep 1 && serverless offline --httpPort 4000 --noTimeout --reloadHandler' --initial --polling", }, "keywords": [], "dependencies": { "@aws-sdk/client-s3": "^3.864.0", "@sendgrid/mail": "^8.1.4", "@sentry/aws-serverless": "^10.22.0", "@sentry/profiling-node": "^10.22.0", "axios": "^1.7.9", "cli-progress": "^3.12.0", "date-fns": "^4.1.0", "date-fns-tz": "^3.2.0", "ics": "^3.8.1", "jsonwebtoken": "^9.0.2", "jwt-decode": "^4.0.0", "lambda-log": "^3.1.0", "mailparser": "^3.7.2", "mongoose": "8.0.1", "mongoose-paginate-v2": "^1.7.4", "pdfkit": "^0.16.0", "qrcode": "^1.5.4", "seatsio": "^85.10.0", "short-uuid": "^5.2.0", "stripe": "^17.5.0", "uuid": "^11.0.5" }, "devDependencies": { "@eslint/js": "^9.22.0", "@sentry/esbuild-plugin": "^4.6.0", "@types/jest": "^30.0.0", "chokidar-cli": "^3.0.0", "esbuild-visualizer": "^0.7.0", "eslint": "^9.22.0", "globals": "^16.0.0", "husky": "^9.1.7", "jest": "^30.1.3", "lambda-tester": "^4.0.1", "mock-jwks": "1.0.10", "mongodb-memory-server": "8.16.0", "nock": "^13.5.6", "serverless-domain-manager": "^8.0.0", "serverless-dotenv-plugin": "^6.0.0", "serverless-offline": "^14.4.0", "serverless-prune-plugin": "^2.1.0", "ts-jest": "^29.4.2", "tsx": "^4.20.6", "typescript": "^5.9.2" } }Analysis & Observations
Potential Root Causes
Attempted Solutions
pnpm store pruneWorkarounds
serverless package --debug(works but verbose)Expected Behavior
serverless packageshould work consistently regardless of the --debug flag when pnpm dependencies are already installed.Additional Context
serverless support --summaryand gotNo previous command information was foundeven thought I had run the command before and followed instructions