title: AWS CDK: Cannot find module 'typescript'
body: <p>Long story short, I have a mono repo that I have been using for almost a year. I had a hard drive failure and had to reinstall my OS. Now, when I try to do anything with the CDK, I get this error every time.</p>
  <pre><code>Cannot find module 'typescript'
  Require stack:
  - /home/jpsimkins/.npm/_npx/16449/lib/node_modules/ts-node/dist/index.js
  - /home/jpsimkins/.npm/_npx/16449/lib/node_modules/ts-node/dist/repl.js
  - /home/jpsimkins/.npm/_npx/16449/lib/node_modules/ts-node/dist/bin.js
  </code></pre>
  <p>This only affects the <code>cdk synth|diff|deploy</code> command. I have no issues with running tests which caused me even more confusion as I check snapshots.</p>
  <p>At first, I was thinking this has to do with the PATH but I am not sure why this would be an issue now. I did use <code>.husky</code> but have since replaced it with my own system. I only mention this in-case this may be something worth knowing.</p>
  <p>This could be an issue with node_module resolution as I have a <code>node_modules</code> directory in this project and the parent. I am using a mono repo with <code>lerna</code>.  This isn't a lerna issue as this issue only happens when running <code>cdk synth|diff|deploy</code>. A simple test of just creating a bucket will throw that error.</p>
  <p>I'm leaning towards the <code>node_modules</code> resolutions. This is not running where my tsconfig is as all the other scripts are working properly. I'm not sure why CDK is the only one having this issue. I have tested with 4 other binaries (jest, prettier, eslint, and tsc)  and they run just fine. The issue is only with <code>cdk</code>.</p>
  <p>I am using Lerna for the mono repo.</p>
  <p>This is my devDependencies:</p>
  <pre><code>  &quot;devDependencies&quot;: {
      &quot;@aws-cdk/assert&quot;: &quot;1.117.0&quot;,
      &quot;@types/jest&quot;: &quot;^26.0.10&quot;,
      &quot;@types/node&quot;: &quot;10.17.27&quot;,
      &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^4.4.0&quot;,
      &quot;@typescript-eslint/parser&quot;: &quot;^4.4.0&quot;,
      &quot;aws-cdk&quot;: &quot;1.117.0&quot;,
      &quot;eslint&quot;: &quot;7.19.0&quot;,
      &quot;eslint-plugin-jest&quot;: &quot;24.3.1&quot;,
      &quot;eslint-plugin-import&quot;: &quot;2.22.1&quot;,
      &quot;eslint-config-airbnb&quot;: &quot;^18.2.0&quot;,
      &quot;eslint-config-airbnb-typescript&quot;: &quot;^9.0.0&quot;,
      &quot;eslint-config-prettier&quot;: &quot;7.2.0&quot;,
      &quot;eslint-plugin-prettier&quot;: &quot;3.3.1&quot;,
      &quot;eslint-plugin-simple-import-sort&quot;: &quot;6.0.1&quot;,
      &quot;execa&quot;: &quot;^5.0.0&quot;,
      &quot;git-url-parse&quot;: &quot;^11.4.4&quot;,
      &quot;jest&quot;: &quot;^26.4.2&quot;,
      &quot;jest-extended&quot;: &quot;^0.11.5&quot;,
      &quot;listr&quot;: &quot;^0.14.3&quot;,
      &quot;lerna&quot;: &quot;^4.0.0&quot;,
      &quot;lerna-update-wizard&quot;: &quot;^0.17.8&quot;,
      &quot;lint-staged&quot;: &quot;^10.5.4&quot;,
      &quot;prettier&quot;: &quot;^2.2.1&quot;,
      &quot;ts-jest&quot;: &quot;^26.2.0&quot;,
      &quot;ts-node&quot;: &quot;^9.0.0&quot;,
      &quot;typedoc&quot;: &quot;^0.20.25&quot;,
      &quot;typescript&quot;: &quot;~3.9.7&quot;,
      &quot;util&quot;: &quot;^0.12.3&quot;
    },
  </code></pre>
  <p>I installed Typescript globally to see if this would help (I normally use local installs for everything) but it did not.</p>
  <p>I also confirmed that the tsc config is what I expect by running <code>tsc --showConfig</code>:</p>
  <pre><code>{
      &quot;compilerOptions&quot;: {
          &quot;alwaysStrict&quot;: true,
          &quot;declaration&quot;: true,
          &quot;experimentalDecorators&quot;: true,
          &quot;lib&quot;: [
              &quot;es2018&quot;
          ],
          &quot;module&quot;: &quot;commonjs&quot;,
          &quot;noFallthroughCasesInSwitch&quot;: false,
          &quot;noImplicitAny&quot;: true,
          &quot;noImplicitReturns&quot;: true,
          &quot;noImplicitThis&quot;: true,
          &quot;noUnusedLocals&quot;: false,
          &quot;noUnusedParameters&quot;: false,
          &quot;inlineSourceMap&quot;: true,
          &quot;inlineSources&quot;: true,
          &quot;removeComments&quot;: false,
          &quot;strict&quot;: true,
          &quot;strictNullChecks&quot;: true,
          &quot;strictPropertyInitialization&quot;: false,
          &quot;target&quot;: &quot;es2018&quot;,
          &quot;typeRoots&quot;: [
              &quot;/home/jpsimkins/DevOps/oly-iac-mono-repo/aws/development/node_modules/@types&quot;
          ],
          &quot;rootDir&quot;: &quot;./src&quot;,
          &quot;outDir&quot;: &quot;./dist&quot;
      },
      &quot;files&quot;: [
          &quot;./src/index.ts&quot;,
          &quot;./src/stacks/pipeline-test/index.ts&quot;,
          &quot;./src/stacks/pipeline-test/src/pipeline-base.ts&quot;,
          &quot;./src/stacks/pipeline-test/src/pipeline-project.ts&quot;,
          &quot;./src/stacks/s3-replication-sources/index.ts&quot;,
          &quot;./src/stacks/s3-replication-sources/src/s3-replication-sources.ts&quot;,
          &quot;./src/stacks/test-base/index.ts&quot;,
          &quot;./src/stacks/test-base/src/index.ts&quot;,
          &quot;./src/stacks/test-web-bucket/index.ts&quot;,
          &quot;./src/stacks/test-web-bucket/src/main.ts&quot;
      ],
      &quot;include&quot;: [
          &quot;./src&quot;
      ],
      &quot;exclude&quot;: [
          &quot;dist&quot;
      ]
  }
  </code></pre>
  <p>npm log:</p>
  <pre><code>0 info it worked if it ends with ok
  1 verbose cli [
  1 verbose cli   '/home/jpsimkins/.nvm/versions/node/v14.17.4/bin/node',
  1 verbose cli   '/home/jpsimkins/.nvm/versions/node/v14.17.4/bin/npm',
  1 verbose cli   'run',
  1 verbose cli   'TestBase:diff'
  1 verbose cli ]
  2 info using npm@6.14.14
  3 info using node@v14.17.4
  4 verbose run-script [ 'preTestBase:diff', 'TestBase:diff', 'postTestBase:diff' ]
  5 info lifecycle @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8~preTestBase:diff: @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8
  6 info lifecycle @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8~TestBase:diff: @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8
  7 verbose lifecycle @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8~TestBase:diff: unsafe-perm in lifecycle true
  8 verbose lifecycle @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8~TestBase:diff: PATH: /home/jpsimkins/.nvm/versions/node/v14.17.4/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/jpsimkins/DevOps/oly-iac-mono-repo/aws/development/accounts/olympusat-development-dev/us-east-1/node_modules/.bin:/home/jpsimkins/.local/bin:/home/jpsimkins/bin:/home/jpsimkins/.nvm/versions/node/v14.17.4/bin:/home/jpsimkins/.local/bin:/home/jpsimkins/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
  9 verbose lifecycle @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8~TestBase:diff: CWD: /home/jpsimkins/DevOps/oly-iac-mono-repo/aws/development/accounts/olympusat-development-dev/us-east-1
  10 silly lifecycle @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8~TestBase:diff: Args: [
  10 silly lifecycle   '-c',
  10 silly lifecycle   'aws2-wrap --profile $(basename $(dirname $(pwd))) ../../../node_modules/.bin/cdk diff TestBase'
  10 silly lifecycle ]
  11 silly lifecycle @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8~TestBase:diff: Returned: code: 1  signal: null
  12 info lifecycle @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8~TestBase:diff: Failed to exec TestBase:diff script
  13 verbose stack Error: @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8 TestBase:diff: `aws2-wrap --profile $(basename $(dirname $(pwd))) ../../../node_modules/.bin/cdk diff TestBase`
  13 verbose stack Exit status 1
  13 verbose stack     at EventEmitter.&lt;anonymous&gt; (/home/jpsimkins/.nvm/versions/node/v14.17.4/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
  13 verbose stack     at EventEmitter.emit (events.js:400:28)
  13 verbose stack     at ChildProcess.&lt;anonymous&gt; (/home/jpsimkins/.nvm/versions/node/v14.17.4/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
  13 verbose stack     at ChildProcess.emit (events.js:400:28)
  13 verbose stack     at maybeClose (internal/child_process.js:1055:16)
  13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
  14 verbose pkgid @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8
  15 verbose cwd /home/jpsimkins/DevOps/oly-iac-mono-repo/aws/development/accounts/olympusat-development-dev/us-east-1
  16 verbose Linux 5.11.0-25-generic
  17 verbose argv &quot;/home/jpsimkins/.nvm/versions/node/v14.17.4/bin/node&quot; &quot;/home/jpsimkins/.nvm/versions/node/v14.17.4/bin/npm&quot; &quot;run&quot; &quot;TestBase:diff&quot;
  18 verbose node v14.17.4
  19 verbose npm  v6.14.14
  20 error code ELIFECYCLE
  21 error errno 1
  22 error @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8 TestBase:diff: `aws2-wrap --profile $(basename $(dirname $(pwd))) ../../../node_modules/.bin/cdk diff TestBase`
  22 error Exit status 1
  23 error Failed at the @olympusat-devops/aws-development-account--olympusat-development-dev--us-east-1@1.1.8 TestBase:diff script.
  23 error This is probably not a problem with npm. There is likely additional logging output above.
  24 verbose exit [ 1, true ]
  </code></pre>
  <h3>Environment</h3>
  <pre><code> - **CDK CLI Version :**  1.117.0 (build 0047c98)
   - **Module Version :**  1.117.0
   - **Node.js Version :**  v14.17.4
   - **OS               :**  Linux Zeus 5.11.0-25-generic #27~20.04.1-Ubuntu SMP Tue Jul 13 17:41:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
   - **Language (Version):** Typescript (Version 3.9.10)
  </code></pre>
  <p>I even tried to install typescript and the cdk globally. This issue still persists.</p>
  <p>Any insight is appreciated.. I've spend all day trying to fix this and no luck..</p>
  <p>Project Layout:</p>
  <pre><code>├── accounts
  │   ├── olympusat-development-dev
  │   ├── README.md
  │   └── us-east-1/
  │       ├── cdk.context.json
  │       ├── cdk.json
  │       ├── cdk.out
  │       │   └── ...
  │       ├── jest.config.js
  │       ├── node_modules
  │       │   └── @olympusat-devops
  │       │       ├── core -&gt; ../../../../../packages/core
  │       │       ├── oly-bastion -&gt; ../../../../../packages/oly-bastion
  │       │       ├── oly-efs -&gt; ../../../../../packages/oly-efs
  │       │       ├── oly-pipeline -&gt; ../../../../../packages/oly-pipeline
  │       │       ├── oly-pipeline-default-image -&gt; ../../../../../packages/oly-pipeline-default-image
  │       │       ├── oly-pipeline-templates -&gt; ../../../../../packages/oly-pipeline-templates
  │       │       ├── oly-rds-wordpress -&gt; ../../../../../packages/oly-rds-wordpress
  │       │       ├── oly-s3-replication-destination -&gt; ../../../../../packages/oly-s3-replication-destination
  │       │       ├── oly-s3-replication-source -&gt; ../../../../../packages/oly-s3-replication-source
  │       │       ├── oly-vpc -&gt; ../../../../../packages/oly-vpc
  │       │       └── oly-web-bucket -&gt; ../../../../../packages/oly-web-bucket
  │       ├── package.json
  │       ├── README.md
  │       ├── src
  │       │   ├── index.ts
  │       │   └── stacks
  │       │       └── ...
  │       ├── tests
  │       │   └── ...
  │       ├── tsconfig.dev.json
  │       └── tsconfig.json
  ├── lerna.json
  ├── node_modules
  │   ├── ...
  ├── package.json
  ├── package-lock.json
  ├── packages
  │   ├── core
  │   ├── oly-bastion
  │   ├── oly-cloudfront-templates
  │   ├── oly-efs
  │   ├── oly-pipeline
  │   ├── oly-pipeline-default-image
  │   ├── oly-pipeline-templates
  │   ├── oly-rds-wordpress
  │   ├── oly-s3-replication-destination
  │   ├── oly-s3-replication-source
  │   ├── oly-vpc
  │   ├── oly-web-bucket
  │   └── README.md
  ├── README.md
  └── tsconfig.json
  </code></pre>