question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docs should not recommend installing cdk with -g (globally)

See original GitHub issue

https://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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
skinny85commented, May 11, 2021

@skinny85 If TypeScript is not installed globally, there’s no tsc command, and the scripts defined in the default package.json break. We could of course change package.json

@Jerry-AWS that’s not how package.json files work. They do not use global commands - they use commands that are found in the node_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 the typescript package (which our init templates do add), the tsc command will be available from there.

1reaction
hoegertncommented, May 18, 2021

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 for cdk init.

Regarding tsc: It is not needed at all for CDK projects as the cdk.json runs the app with ts-node

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting common AWS CDK issues
npx aws-cdk runs the local version of the AWS CDK Toolkit if one exists. It falls back to the global version when a...
Read more >
How to install AWS CDK (step-by-step guide)
To install AWS CDK, run the following command in your terminal: npm install -g aws-cdk . This will install the AWS CDK package...
Read more >
Uninstalling packages and dependencies - npm Docs
To uninstall an unscoped global package, on the command line, use the uninstall command with the -g flag. Include the scope if the...
Read more >
How to upgrade CDK to latest version - DEV Community ‍ ‍
npm install -g aws-cdk@latest ... yarn global upgrade aws-cdk ... I searched for contructs and this was the best I could find.
Read more >
Error: EACCES: permission denied - node.js - Stack Overflow
Test: Download a package globally without using sudo. npm install -g jshint. Instead of steps 2-4, you can use the corresponding ENV variable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found