Docs should not recommend installing cdk with -g (globally)
See original GitHub issuehttps://docs.aws.amazon.com/cdk/latest/guide/work-with.html#work-with-prerequisites recommends installing cdk and typescript with -g.
As someone who cares about reproducible builds and knows little about node.js, I found this page 100x more useful than the official docs:
https://www.endoflineblog.com/cdk-tips-01-how-to-use-local-cdk-commands
That says to use npx
to init a new project, and npm run cdk
afterwards. (And npm ci
to reinstall cdk for an existing project)
I made myself this shell alias and it has raised my productivity immensely:
alias ncdk='npm run cdk --'
I think the default README.md generated by new projects should also say npm run cdk
instead of cdk
.
It makes no sense to recommend global cdk installs especially when you are releasing an incompatible major version 2 as we speak. Global tooling installs is also a violation of 12factor.net (point 2).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:12 (5 by maintainers)
Top GitHub Comments
@Jerry-AWS that’s not how
package.json
files work. They do not use global commands - they use commands that are found in thenode_modules/.bin
directory, which gets automatically added to the PATH when executing a script from them.More information: https://docs.npmjs.com/cli/v7/using-npm/scripts#path
So, as long as there is a dependency in the
package.json
file on thetypescript
package (which our init templates do add), thetsc
command will be available from there.If you use
npx cdk
it will use the locally installed one and if non is existent it will temporarily install a global one for this call, which is perfect forcdk init
.Regarding
tsc
: It is not needed at all for CDK projects as the cdk.json runs the app with ts-node