TypeStrong / TypeStrong/ts-loader

No error trace on webpack, wrong line numbers make errors unsolvable

Open
#1,395 4 comments 1 reaction 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

So I've set up a Vue project with Webpack, then I installed the proper loaders and moved to TypeScript inside my SFCs. It's all running good, except that the TS errors caught during build time are shown accordingly to compiled files, thus making debugging difficult.

My Webpack config looks like this:

// ...
module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: 'vue-loader',
      },
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        options: {
          appendTsSuffixTo: [/\.vue$/]
        }
      },
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'postcss-loader'
        ]
      },
      {
        test: /\.png$/,
        use: 'file-loader'
      }
    ]
  }
}

So, the .vue files are converted by the ts-loader during build time, and I end up getting errors like this in my Webpack output:

ERROR in /home/mega/savitri/packages/frontend/src/components/molecules/CSearch/CSearch.vue.ts
52:29-59
[tsl] ERROR in /home/mega/savitri/packages/frontend/src/components/molecules/CSearch/CSearch.vue.ts(52,30)
      TS2571: Object is of type 'unknown'.
ts-loader-default_0c5a263502dc9404

ERROR in /home/mega/savitri/packages/frontend/src/components/molecules/CSearch/CSearch.vue.ts
57:27-39
[tsl] ERROR in /home/mega/savitri/packages/frontend/src/components/molecules/CSearch/CSearch.vue.ts(57,28)
      TS2571: Object is of type 'unknown'.
ts-loader-default_0c5a263502dc9404

ERROR in /home/mega/savitri/packages/frontend/src/components/molecules/CSearch/CSearch.vue.ts
66:27-39
[tsl] ERROR in /home/mega/savitri/packages/frontend/src/components/molecules/CSearch/CSearch.vue.ts(66,28)
      TS2571: Object is of type 'unknown'.
ts-loader-default_0c5a263502dc9404

ERROR in /home/mega/savitri/packages/frontend/src/components/molecules/CSearch/CSearch.vue.ts
74:42-54
[tsl] ERROR in /home/mega/savitri/packages/frontend/src/components/molecules/CSearch/CSearch.vue.ts(74,43)
      TS2571: Object is of type 'unknown'.
ts-loader-default_0c5a263502dc9404

Searching around I've came across several answers regarding source maps, but as far as I'm aware this serves devtools debugging only. How can I get the errors to match original files in order to solve them?

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

Reproduce the reported Vue, Webpack, and ts-loader setup from the issue, then inspect how ts-loader reports TypeScript diagnostics for transformed .vue files. No repository files or tests are named; done means build errors point to the original .vue source and line numbers rather than the generated .vue.ts file.

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
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.