TypeStrong / TypeStrong/ts-loader

ts-loader fails on stage 3 decorators: Unexpected character '@'

Open
#1,631 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.5k
Forks
439
Avg merge
17h 17m
Merged PRs (30d)
2

Description

Expected Behaviour

Since TS 5 we can create stage 3 decorators. Using webpack and ts-loader they should be compiled without issue.

Actual Behaviour

The build fails with Unexpected character '@'

Module parse failed: Unexpected character '@' (21:0)
File was processed with these loaders:
 * ../../node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
Steps to Reproduce the Problem

https://stackblitz.com/edit/webpack-terser-ztxsth?file=src%2Findex.ts,tsconfig.json,package.json

Location of a Minimal Repository that Demonstrates the Issue.

Please see the link above

Workaround

I posted this issue on Stack Overflow and received a workaround where useDefineForClassFields must be set to false. However, this enables legacy behaviour. It would be nice if this issue could be resolved so the workaround is no longer needed. If there's another solution to the issue, I would also be happy to hear it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked StackBlitz reproduction and inspect src/index.ts, tsconfig.json, and package.json with ts-loader and webpack. Confirm the failure with stage 3 decorators and determine what change allows compilation without setting useDefineForClassFields to false. Done means the reproduction builds without the legacy-behavior workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.