TypeStrong / TypeStrong/ts-loader

NormalModuleReplacementPlugin doesn't play nice with ts-loader

Open
#838 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Expected Behaviour

When I implement the pattern for the NormalModuleReplacementPlugin, I expect that the ts-loader would be aware of the configuration and help swallow the compiler error so the compilation would finish.

Actual Behaviour

Because './config/config-APP_TARGET' does not actually exist, the compiler throws an error:

    ERROR in ./ClientApp/boot.ts
    Module build failed (from ./node_modules/ts-loader/index.js):
    Error: Typescript emitted no output for D:\GitHub\NMRP-Plus-TypeScript-Repro\WebPack-NMRP-Repro\ClientApp\boot.ts.
        at successLoader (D:\GitHub\NMRP-Plus-TypeScript-Repro\WebPack-NMRP-Repro\node_modules\ts-loader\dist\index.js:41:15)
        at Object.loader (D:\GitHub\NMRP-Plus-TypeScript-Repro\WebPack-NMRP-Repro\node_modules\ts-loader\dist\index.js:21:12)

    ERROR in D:\GitHub\NMRP-Plus-TypeScript-Repro\WebPack-NMRP-Repro\ClientApp\boot.ts
    ./ClientApp/boot.ts
    [tsl] ERROR in D:\GitHub\NMRP-Plus-TypeScript-Repro\WebPack-NMRP-Repro\ClientApp\boot.ts(1,20)
          TS2307: Cannot find module './config/config-APP_TARGET'.

The code executes locally anyway, but because webpack throws a failed error code at this point, automated build systems like Azure Pipelines fail.

Workaround:

You have to add a config-APP_TARGET.ts file to the config folder, with a blank exported module mirroring your actual config module, so that the compiler does not error out.

It would be really nice if this workaround was not necessary.

Steps to Reproduce the Problem

See repro below.

Location of a Minimal Repository that Demonstrates the Issue.

https://github.com/CloudNimble/NMRP-Plus-TypeScript-Repro

I hope this information helps someone who runs into the same problem, and I hope it can ultimately be fixed so that the pattern in the documentation can be implemented as-is.

Thanks!

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 NMRP-Plus-TypeScript-Repro with NormalModuleReplacementPlugin and ts-loader, then inspect ClientApp/boot.ts and the loader entry points shown in node_modules/ts-loader/index.js and dist/index.js. Done means the webpack compilation completes without the TS2307 missing-module or “Typescript emitted no output” errors, without requiring config-APP_TARGET.ts.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, webpack
Domain
build-system
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.