本文介绍了tsc-watch 消耗 TSC_NONPOLLING_WATCHER 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事微服务集成项目.我同时使用 8 个打字稿服务tsc-watch --preserveWatchOutput --onSuccess 'node build/index.js'.

I am working on microservice integration project. I run 8 typescript services at the same time using tsc-watch --preserveWatchOutput --onSuccess 'node build/index.js'.

这些进程占用了我 70% 的 CPU,即使我根本没有编写源代码.我认为对正在进行的更改进行了一些轮询,并在谷歌上搜索将环境变量 TSC_NONPOLLING_WATCHER 设置为1"将停止轮询.

The processes consume 70% of my CPU, even when I make no source code at all. I figured there is some polling for changes going on and googled that setting environment variable TSC_NONPOLLING_WATCHER to "1" will stop the polling.

这是提示的来源:https:///medium.com/@julioromano/writing-typescript-on-a-laptop-this-might-improve-your-battery-life-f503dd16f019

然而,它似乎根本没有影响.此外,作者提到了tsc -w"而不是 tsc-watch.我不太明白 tsc -w 和 tsc-watch 之间有什么区别.

It does however seem to have no effect at all. Also, the author mentions "tsc -w" and not tsc-watch. I do not quite understand what the difference is between tsc -w and tsc-watch.

如果有任何帮助,我将不胜感激.

I would be thankful for any help.

推荐答案

Update 1 tsconfig.json 需要

我遇到了类似的问题 并将通过正确设置环境变量 TSC_NONPOLLING_WATCHER="1" 来解决它.

I run into a similar problem and are going to solve it by setting the environment variable TSC_NONPOLLING_WATCHER="1" properly.

就我而言,我不得不通过

In my case i had to adjust .zprofile via

export TSC_NONPOLLING_WATCHER="1"

您可以通过 echo $TSC_NONPOLLING_WATCHER 在命令 shell 中对其进行测试.

You can test it in a command shell via echo $TSC_NONPOLLING_WATCHER.

替代方案

如果这没有帮助,请尝试将 tsconfig.json 文件设置为以下内容:

If this doesn't help try to set the tsconfig.json files to the following:

"watchOptions": {
    // Use native file system events for files and directories
    "watchFile": "useFsEvents",
    "watchDirectory": "useFsEvents",

    // Poll files for updates more frequently
    // when they're updated a lot.
    "fallbackPolling": "dynamicPriority"
}

这些选项来自:https://www.typescriptlang.org/docs/handbook/configuring-watch.html,我强烈建议您在进行任何更改之前通读一遍.

These options come from: https://www.typescriptlang.org/docs/handbook/configuring-watch.html and I highly suggest reading through it before doing any changes.

tsc 与 tsc-watch

关于tsc -wtsc-watch的区别github上的项目声明,我引用:

About the difference between tsc -w and tsc-watch the project on github claimes and I quote:

  • tsc-watch 正在使用当前安装的 TypeScript 编译器.
  • tsc-watch 并没有改变编译器,只是增加了新的参数,编译是一样的,其他参数都是一样的.

因此 tsc 的所有设置在 tsc-watch 中都应该像您的情况一样正常工作.

So all settings for tsc should work as well in tsc-watch like in your case.

这篇关于tsc-watch 消耗 TSC_NONPOLLING_WATCHER 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 11:56