简体   繁体   中英

ts-node and custom loaders

Is it possible to use ts-node and a custom loader? In the docs I only see a way to enable esm compatibility .

ts-node --esm my-file.ts

I am trying to use a custom loader for testing an ESM module but I don't want to use node to compile each time since this is for a test suite. The way to use (multiple) loaders in node is like so

node --loader=esm --loader=testdouble my-file.js

Sure: Just use ts-node/esm as the loader value. This is documented as an environment variable in ts-node 's README :

Or, if you require native ESM support:

 NODE_OPTIONS="--loader ts-node/esm"

This tells any node processes which receive this environment variable to install ts-node's hooks before executing other code.

Be sure to understand:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM