简体   繁体   English

ts-node 和自定义加载器

[英]ts-node and custom loaders

Is it possible to use ts-node and a custom loader?是否可以使用 ts-node 和自定义加载器? In the docs I only see a way to enable esm compatibility .在文档中,我只看到了一种启用esm 兼容性的方法。

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.我正在尝试使用自定义加载程序来测试 ESM 模块,但我不想每次都使用节点进行编译,因为这是针对测试套件的。 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.当然:只需使用ts-node/esm作为加载器值。 This is documented as an environment variable in ts-node 's README :ts-node的 README 中记录为环境变量

Or, if you require native ESM support:或者,如果您需要本机 ESM 支持:

 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.这告诉任何接收此环境变量的节点进程在执行其他代码之前安装 ts-node 的钩子。

Be sure to understand:请务必了解:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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