question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Whats the trick for getting chalk workging with TS

See original GitHub issue

I have a very simple test script

src/index.ts

import * as chalk from 'chalk'

console.log(`${chalk.green('Hello TypeScript world!')}`)

tsconfig.json image

After building with webpack 4, everything appears to work, but the chalked output is not honoring color definition

image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

28reactions
SamVerschuerencommented, Jul 1, 2018

Oh, apparently it’s as simple as setting the target in your webpack.config.js to node.

var path = require('path');

module.exports = {
    entry: './src/index.ts',
    devtool: 'inline-source-map',
    target: 'node',
    output: {
        path: path.resolve(__dirname, 'build'),
        filename: 'bundle.js'
    },
    module: {
        rules: [
            {
                use: 'ts-loader',
                test: /\.ts?$/
            }
        ]
    }
}

Sidenote: The correct import for Chalk in TypeScript is import chalk from 'chalk';. It comes bundled with TypeScript type definitions so you don’t need to do anything extra for the typings to work. You don’t need to add something to tsconfig.json like you did.

9reactions
tmorellcommented, Oct 8, 2019

I am not using it with webpack. chalk is exported as default by the module, so it should be imported using: import chalk from "chalk";

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Can I Get My Chalk Marker Working Again - Cohas
What You Should Do Instead. Prepare a surface that you don't mind getting ink on. This could be paper towels, newspaper, or even...
Read more >
Window Chalk Art | Tips and Tricks - YouTube
This will help you with your chalk window projects. ... you don' t pay any more for these items but i might get...
Read more >
30 Chalk Couture Tips and Tricks Every Crafter Needs to Know
Don't PANIC and don't PULL. Here's what you need to do- immediately take your folded transfer to the sink and run cold water...
Read more >
My #1 Most-Used Signage Hack (Chalk Transfer)
Let's Get Started! For starters, you're going to need your design. It can be digital or hand drawn. It can be on transfer...
Read more >
10 Chalkboard Tips and Tricks - The Lilypad Cottage
From picking fonts to what chalk and tools to use, everything you need to know. ... DON'T use paper towel—you will get little...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found