search

Home  >  Q&A  >  body text

node.js - 使用babel后console.log中输出“\033”时程序报错 如何解决

console.log('\033[33m[' + myDate.toLocaleTimeString() + ']\033[0m '+'新用户[ID '+mine.uid+']登记成功');

console.log时想要文字带上色彩,所以033[33m[这样的代码,但增加babel组件使用自动转换,启动时提示在这里报错
只能暂时再加一条斜杠先让程序跑起来,但命令行中色彩效果全没了。

console.log('\\033[33m[' + myDate.toLocaleTimeString() + ']\\033[0m '+'新用户[ID '+mine.uid+']登记成功');

高洛峰高洛峰2767 days ago708

reply all(1)I'll reply

  • 迷茫

    迷茫2017-04-17 15:52:22

    No one invited me, I came by myself. . . .

    This problem should be regarded as a relatively niche problem. I happened to encounter it before when doing color output. At that time, it was not a problem caused by babel conversion, but the strict mode enabled by nodejs node --use-strictproblem. node --use-strict出的问题。

    033换成x1b

    Just replace 033 with x1b🎜
    console.log('\x1b[33m 23333');

    reply
    0
  • Cancelreply