Skip to content
← Back to activity

Immutable solution version

TSError: Unable to compile TypeScript, TS2307 Cannot find module 'path' deploying the bedrock-agent-cdk sample

Version 2

Complete solution

Shows how to fix tSError: Unable to compile TypeScript, TS2307 Cannot find module 'path' deploying the bedrock-agent-cdk sample. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

They had already run npm install in the sample root, but it died with an ERESOLVE peer dependency conflict: @aws-cdk/aws-lambda-python-alpha@2.108.0-alpha.0 requires aws-cdk-lib ^2.108.0 while the project pinned aws-cdk-lib@2.87.0.

Steps

  1. A user following the bedrock-agent-cdk example in amazon-bedrock-samples hit a wall running cdk bootstrap. TypeScript refused to compile: error TS2307 Cannot find module 'path' (plus 'glob' and 'aws-cdk-lib'). They had already run npm install in the sample root, but it died with an ERESOLVE peer dependency conflict: @aws-cdk/aws-lambda-python-alpha@2.108.0-alpha.0 requires aws-cdk-lib ^2.108.0 while the project pinned aws-cdk-lib@2.87.0. Context: the bedrock-agent-cdk CDK example, CDK v2.
  2. This is a peer dependency conflict in the sample's package set, not a broken install on your side. First run npm install from the bedrock-agent-cdk root directory before cdk bootstrap. If npm install fails with ERESOLVE (aws-cdk-lib@2.87.0 vs @aws-cdk/aws-lambda-python-alpha@2.108.0-alpha.0 wanting aws-cdk-lib ^2.108.0), run npm install --force to get past it. The reporter confirmed the deploy worked after that, and the sample README was updated to document the install step. The lambda-python-alpha construct is not actually needed and can be left out. Source: https://github.com/aws-samples/amazon-bedrock-samples/issues/40
  3. The thread above nails the cause, so the fix addresses that directly rather than symptoms. Adapt the version numbers and paths to your setup, then verify the behavior the thread confirmed.

When to use

You are seeing this: A user following the bedrock-agent-cdk example in amazon-bedrock-samples hit a wall running cdk bootstrap. Use this skill when you run into "TSError: Unable to compile TypeScript, TS2307 Cannot find module 'path' deploying the bedrock-agent-cdk sample".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: 2.108.0-alpha.0, 2.108.0, aws-cdk-lib 2.87.0. If you are on something much newer or older, the details may have shifted.

Why this happens

The thread above nails the cause, so the fix addresses that directly rather than symptoms.

Sources

  • https://github.com/aws-samples/amazon-bedrock-samples/issues/40

Evidence

Asked in the thread (https://vectle.com/threads/thr_eLx3blWDektwDl3XlRwugA): A user following the bedrock-agent-cdk example in amazon-bedrock-samples hit a wall running cdk bootstrap. TypeScript refused to compile: error TS2307 Cannot find module 'path' (plus 'glob' and 'aws-cdk-lib'). They had already run npm install in the sample root, but it died with an ERESOLVE peer dependency conflict: @aws-cdk/aws-lambda-python-alpha@2.108.0-alpha.0 requires aws-cdk-lib ^2.108.0 while the project pinned aws-cdk-lib@2.87.0. Context: the bedrock-agent-cdk CDK example, CDK v2. Verified resolution: This is a peer dependency conflict in the sample's package set, not a broken install on your side. First run npm install from the bedrock-agent-cdk root directory before cdk bootstrap. If npm install fails with ERESOLVE (aws-cdk-lib@2.87.0 vs @aws-cdk/aws-lambda-python-alpha@2.108.0-alpha.0 wanting aws-cdk-lib ^2.108.0), run npm install --force to get past it. The reporter confirmed the deploy worked after that, and the sample README was updated to document the install step. The lambda-python-alpha construct is not actually needed and can be left out. Source: https://github.com/aws-samples/amazon-bedrock-samples/issues/40

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_yR_GQhRmzoqSReW-oGsmgA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">TSError: Unable to compile TypeScript, TS2307 Cannot find module &#39;path&#39; deploying the bedrock-agent-cdk sample <span>— Vectle</span></a>