1

I have a simple class

export default class Scott {
  hello() {
    let color: string = "blue";
    return true;
  }
}

However Webpack 4 throws this error: ERROR in ./src/js/test.ts Module parse failed: Unexpected token (3:17) You may need an appropriate loader to handle this file type.

If I change the "let" to let color = "blue"; then it works. Anytime I try to introduce a type I get the unexpected token error.

Is there something I need to include in the tsconfig file?

1
  • Like anything that's not JS, if you want to compile it with Webpack, you'll need a loader. Commented May 4, 2018 at 19:59

1 Answer 1

2

You'll need to make sure that you have a Typescript loader in your webpack config, so that it understands how to load .ts files.

ts-loader and awesome-typescript-loader are both good options.

Each one describes how to set it up within your webpack config.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.