Run Any Version of a Node Tool with npx

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

As node projects evolve, new features are added all the time. This results in different errors or results as you're migrating from one version to another. npx allows you to try out any version you want by simply adding the version number to the project you're using. This lesson covers using the TypeScript compiler through a different versions as async function support was added.

[00:00] Let's create a TypeScript file that has an async function in it, so async function foo, and then just write that out to an index file, so the entire contents of that file is just async function foo.

[00:13] With NPX, I can try out different versions. If I try out 1.6 of TypeScript and then pass in my file, you'll see that I get this specific error saying they're only available with ES6, and it's asking me to specify experimental async functions, so let's try with TypeScript 1.7.

[00:35] This time you see we get that first error, but we don't get that second error. That's only because we changed versions of TypeScript, which has change support for async functions over time.

[00:45] If we try with a much later version of TypeScript like 2.4, you'll see that it handles the async function just fine, and doesn't throw any errors. If I just try TypeScript without any version number in there, it'll use the latest version, and that won't produce any errors either.

[01:05] We can check the output, which would be index.js, and you'll see it compiled it down using that generator polyfill to support async functions. Or if you know that your browser supports async functions, you can always pass in command line arguments like target ES2017, pass in index.ts. Then our output would be the exact same file.

egghead
egghead
~ 15 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today