From the course: TypeScript Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Executing modular code

Executing modular code

- [Jess] If you're learning TypeScript, you're probably looking to run your code in either the browser or Node.js. Unfortunately, the code I've been showing won't actually run in either of those environments as it is, but in this video, I'll show you how to fix that. I'll start with Node.js, since that's the easiest. As of this recording, Node.js expects module imports to use a different syntax than the one I've been showing here, which means that if I try to build and run this application, I see this error. Even though it's not obvious, this is Node's way of telling me that it doesn't support this import syntax in .js files. However, having TypeScript output the code that can run in Node is as simple as tweaking a TypeScript config setting. Simply set the module configuration setting to commonJS, the type of module system that Node uses. Now, when I save this, run the TypeScript compiler again, and check out the output…

Contents