After using a mono repo for nearly a year, I encountered a hard drive failure that forced me to reinstall my OS. Now, every time I attempt to use the CDK, I encounter the following error:
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
This issue is specific to the cdk synth|diff|deploy
command. Running tests does not pose any problems, which added to my confusion as I investigated snapshots.
Initially, I suspected a PATH-related problem, but I couldn't understand why it would arise now. Although I previously used .husky
, I have since developed my own system. I mention this in case it holds any significance.
The root of the issue might lie in node_module resolution, particularly due to the presence of a node_modules
directory both within this project and its parent. This project utilizes a mono repo with lerna
. It's worth noting that this isn't an issue with lerna, as the problem arises only when executing cdk synth|diff|deploy
. Even a simple task like creating a bucket triggers the same error.
I suspect the problem revolves around node_modules
resolutions. The execution doesn't align with where my tsconfig resides, while all other scripts function correctly without issues. The inconsistency puzzles me, especially given that I've successfully tested four other binaries (jest, prettier, eslint, and tsc), all of which run smoothly. The hurdle appears isolated to cdk
.
Lerna plays a role in managing the mono repo setup.
The devDependencies list includes:
"devDependencies": {
"@aws-cdk/assert": "1.117.0",
"@types/jest": "^26.0.10",
"@types/node": "10.17.27",
"@typescript-eslint/eslint-plugin": "^4.4.0",
"@typescript-eslint/parser": "^4.4.0",
"aws-cdk": "1.117.0",
...
},
Despite installing Typescript globally--a departure from my usual preference for local installs across the board--the issue persists.
Running tsc --showConfig
confirmed that the tsconfig settings align with expectations:
{
"compilerOptions": {
...
},
...
}
Examining the npm log revealed:
...
Environment
- **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)
In an attempt to resolve the issue, even resorting to globally installing typescript and the cdk didn't yield success.
Your insights and suggestions are highly appreciated. I've dedicated an entire day trying to troubleshoot this to no avail.
Project Layout:
├── accounts
│ ├── olympusat-development-dev
│ ├── README.md
│ └── us-east-1/
...