I use chalk to write a simple script, and bundle the code using webpack.
The code print colored text before bundle, but print text without color after bundle
using webpack.
The test code is:
const chalk = require('chalk')
function main() {
  console.log(chalk.blue('chalk'))
}
main()
The webpack.config.js:
const path = require('path')
module.exports = {
  mode: 'production',
  entry: path.resolve(__dirname, 'src/main.js'),
  output: {
    filename: 'bundle.js',
  },
 
  resolve: {
    extensions: ['.js'],
  },
}
What happened ?
                        
For me was in the webpack configuration, I was compiling for web target instead of node target =]