-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the bug
When using nodeModules with pnpm, CDK creates a pnpm-workspace.yaml in the bundling temp directory (added in #21911 to fix #21910). This causes pnpm to treat the bundling directory as a standalone workspace root, which prevents it from inheriting .npmrc configuration from parent directories. This breaks authentication for packages from private registries (e.g., AWS CodeArtifact).
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
When nodeModules is specified, pnpm install in the bundling directory should be able to authenticate with private registries configured in the project's .npmrc.
Current Behavior
pnpm install fails with 401 Unauthorized errors when trying to fetch packages (or their dependencies) from private registries, because the bundling directory's pnpm-workspace.yaml prevents pnpm from finding the project's .npmrc with auth tokens.
Reproduction Steps
- Create a pnpm monorepo with a private registry configured in
.npmrc:
@myorg:registry=https://my-private-registry.example.com/npm/
//my-private-registry.example.com/npm/:_authToken=<token>
- Add a
NodejsFunctionwithnodeModulesreferencing a package from the private registry:
new NodejsFunction(this, 'MyFunction', {
entry: 'src/handler.ts',
bundling: {
nodeModules: ['@myorg/my-private-package'],
},
});
-
Run
cdk synth -
Observe 401 errors during bundling because pnpm can't find the auth token
Possible Solution
- Copy the project's
.npmrcto the bundling directory alongsidepnpm-workspace.yaml - Or document this limitation and the workaround (use global
~/.npmrcorcommandHooks.beforeInstallto copy.npmrc)
Additional Information/Context
Workarounds:
- Store auth tokens in global
~/.npmrcinstead of project.npmrc - Use
commandHooks.beforeInstallto copy.npmrcto the bundling directory
AWS CDK Library version (aws-cdk-lib)
2.194.0
AWS CDK CLI version
2.1015.0
Node.js Version
24
OS
MacOS 15.7.3 (24G419)
Language
TypeScript
Language Version
No response
Other information
No response