0

windows PowerShell 上で node コマンドを実行すると
[90m というのがついて非常に見づらいです

bash 上だと色が変わったり太字になったりするコードだと思うんですが消す方法はないでしょうか
色が変わってくれれば理想なんですが

PS D:\js\network-test> node test.js
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'puppeteer'
Require stack:
- D:\js\network-test\test.js
[90m    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)[39m
[90m    at Function.Module._load (node:internal/modules/cjs/loader:778:27)[39m
[90m    at Module.require (node:internal/modules/cjs/loader:999:19)[39m
[90m    at require (node:internal/modules/cjs/helpers:102:18)[39m
    at Object.<anonymous> (D:\js\network-test\test.js:1:19)
[90m    at Module._compile (node:internal/modules/cjs/loader:1095:14)[39m
[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)[39m
[90m    at Module.load (node:internal/modules/cjs/loader:975:32)[39m
[90m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)[39m
[90m    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)[39m {
  code: [32m'MODULE_NOT_FOUND'[39m,
  requireStack: [ [32m'D:\\js\\network-test\\test.js'[39m ]
}

Node.js v17.0.1

1 件の回答 1

1

それはANSI/VT100エスケープシーケンスで、ちょっと前の記事ではデフォルトではオフになっているとあります。
Colored text output in PowerShell console using ANSI / VT100 codes
回答から

While console windows in Windows 10 do support VT (Virtual Terminal) / ANSI escape sequences in principle, support is turned OFF by default.
You have three options:

ということで以下3つのオプションがあるようです。

  • レジストリを書き変える
  • 処理の中でSetConsoleMode()APIを呼ぶ
  • 出力結果をOut-Hostスクリプトで表示する

詳細は上記記事&回答を参照してください。

ただ、PowerShellの最近の版(7.2とか?)やWindows Terminalあたりを使うとデフォルトで有効になっている可能性も考えられるので、そちらを試してみるのが良いかもしれません。

1
  • ありがとうございます! windows terminal をインストールしてみたら色が出ました!
    – user35303
    2022年2月13日 8:16

この質問に回答するには、ログインする必要があります。