Open Edweis opened 1 year ago
thank you for filing the issue @Edweis
I believe serverless-offline is running in its own child_process and the colours are not appropriately passed (like there).
serverless-offline
switched to using worker threads from v9
onwards. that said, I didn't even notice that console.log is using colors in the main process. that might be something node.js itself has to fix. if you could do some research on that topic that would be much appreciated.
on a similar note, what I noticed, when developers are using third party color modules (e.g. chalk), that those most of the time don't work out of the box, as the terminal color detection does not seem to work for worker threads. one can force using colors with an environment variable FORCE_COLOR='true'
. something we should add to the docs.
example:
// this should work
console.log('\x1b[36m%s\x1b[0m', 'I am cyan');
// this probably does not, unless we set process.env.FORCE_COLOR
// (either by code, or setting the env in the serverless config,
// or in the local dev environment by using the flag `localEnvironment`)
import chalk from 'chalk';
console.log(chalk.blue('Hello world!'));
Thank you. I had a quick look and I found that colors should be passed into the worker at src/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js
. However the colors from the workers are not set. My guess is that util.format
used in console.xxx()
does not detect the TTY (since the worker is technically not a TTY), hence not applying colors.
I might investigate more when I'll have more time.
Bug Report
Using node 16.x,
console.log({ hello : 1 })
Using
serverless-offline@8
it worked the same way:Upgrading to
serverless-offline@8
,serverless-offline@9
, orserverless-offline@10
, orserverless-offline@11
Sample Code
Environment
serverless
version: 3.24.1serverless-offline
version: 11.3.0node.js
version: v16.18.0OS
: Mac OS 13Possible Solution
I believe
serverless-offline
is running in its ownchild_process
and the colours are not appropriately passed (like there).I'll be happy to do a PR is someone can point me here
serverless-offline
is instantiated.