When not to install packages globally

One last note before we dive into TypeScript.

In the first chapter, we installed the npm package for TypeScript globally. Actually, it is not something that we recommend, apart from for demonstration purposes; we only did this to quickly get started.

Now that we are going to create actual projects, we should use a cleaner and safer alternative. Having TypeScript installed globally is useful for small tests, but can cause harm in real projects. If each developer in a team installs TypeScript globally and you rely on that, what guarantee do you have that each and every developer in your team will still have the same version of TypeScript installed in a month? Here's a hint: none.

In most cases, you should prefer to install npm packages locally by listing them in package.json, whether that package is a library, a framework, or a tool used in your build chain. By doing so, npm can take care of installing everything at once, which is already nice, but more importantly, it also ensures that anyone working on the project will get the exact same set of dependencies as you do (assuming that your dependency versions are correctly defined and that you use a package-lock.json file or similar).

For tools such as TypeScript, webpack, and the like, what you should do is leverage the scripts section of package.json in order to make sure to invoke the version that you expect and not another one. We'll do exactly that for our project in a second.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.107.96