Search code examples
node.jstypescriptprotractorcommonjs

What's the difference between requiring ts-node and ts-node/register


I'm doing some e2e tests for an angular app using protractor and typescript. During the setup i found out that i have to use:

require("ts-node/register")

Since I'm new to node.js I'm wondering why the "/register" is needed here and why i can't just use require("ts-node")?


Solution

  • It depends on what you want to load in your file:

    • require("ts-node") loads the whole ts-node library. You can then access the register sub module by doing tsNode.register

    • require("ts-node/register") only loads the sub module register of the ts-node library

    Keep in mind that require("ts-node") increases the size of the bundle of the application as the whole library is loaded, so prefer the notation require("ts-node/register") to load only what you need.