(cdk): Cannot find module 'typescript'
See original GitHub issue❓ General Issue
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 everytime.
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 only affects the cdk synth|diff|deploy
command. I have no issues with running tests which caused me even more confusion as I check snapshots.
I am thinking this has to do with the PATH but I am not sure why this would be an issue now. I did use .husky
but have since replaced it with my own system. I only mention this in-case this may be something worth knowing.
This could also be an issue with node_module resolution as I have a node_modules
directory in this project and the parent. I am using a mono repo with lerna
. This isn’t a lerna issue as this issue only hapens when running cdk synth|diff|deploy
. A simple test of just creating a bucket will throw that error.
This is my devDependencies:
"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",
"eslint": "7.19.0",
"eslint-plugin-jest": "24.3.1",
"eslint-plugin-import": "2.22.1",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-airbnb-typescript": "^9.0.0",
"eslint-config-prettier": "7.2.0",
"eslint-plugin-prettier": "3.3.1",
"eslint-plugin-simple-import-sort": "6.0.1",
"execa": "^5.0.0",
"git-url-parse": "^11.4.4",
"jest": "^26.4.2",
"jest-extended": "^0.11.5",
"listr": "^0.14.3",
"lerna": "^4.0.0",
"lerna-update-wizard": "^0.17.8",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"ts-jest": "^26.2.0",
"ts-node": "^9.0.0",
"typedoc": "^0.20.25",
"typescript": "~3.9.7",
"util": "^0.12.3"
},
Any insight is appreciated… I’ve spend all day trying to fix this and no luck…
I installed Typescript globally to see if this would help (I normally use local installs for everything) but it did not.
I also confirmed that the tsc config is what I expect by running tsc --showConfig
:
{
"compilerOptions": {
"alwaysStrict": true,
"declaration": true,
"experimentalDecorators": true,
"lib": [
"es2018"
],
"module": "commonjs",
"noFallthroughCasesInSwitch": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"inlineSourceMap": true,
"inlineSources": true,
"removeComments": false,
"strict": true,
"strictNullChecks": true,
"strictPropertyInitialization": false,
"target": "es2018",
"typeRoots": [
"/home/jpsimkins/DevOps/oly-iac-mono-repo/aws/development/node_modules/@types"
],
"rootDir": "./src",
"outDir": "./dist"
},
"files": [
"./src/index.ts",
"./src/stacks/pipeline-test/index.ts",
"./src/stacks/pipeline-test/src/pipeline-base.ts",
"./src/stacks/pipeline-test/src/pipeline-project.ts",
"./src/stacks/s3-replication-sources/index.ts",
"./src/stacks/s3-replication-sources/src/s3-replication-sources.ts",
"./src/stacks/test-base/index.ts",
"./src/stacks/test-base/src/index.ts",
"./src/stacks/test-web-bucket/index.ts",
"./src/stacks/test-web-bucket/src/main.ts"
],
"include": [
"./src"
],
"exclude": [
"dist"
]
}
npm log:
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.<anonymous> (/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.<anonymous> (/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 "/home/jpsimkins/.nvm/versions/node/v14.17.4/bin/node" "/home/jpsimkins/.nvm/versions/node/v14.17.4/bin/npm" "run" "TestBase:diff"
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 ]
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)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:11
Top GitHub Comments
We had the same problem, started happening in
ts-node@10.2.0
for usProblem: in our
cdk.json
we had thisbut we didn’t have the
ts-node
in the devDependencies (or dependancies) so every time, in our CI/CD it would download the latestts-node
Solution:
yarn add -D ts-node@~10.1.0
cdk.json
set theapp
key to:This issue seems to be due to
node_modules
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 withcdk
.I even tried to install typescript globally and still the same error persists.