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 ?
It could be a problem with your individual computer or terminal. I had a similar situation, where a simple use of
chalkwasn't working. Once I stopped using Solarized themes in my terminal preferences,chalkworked as expected.(In my searching for solutions, there were a few other solutions out there for weird behavior, solved by such things as uninstalling iTerm2.)