Description
Current behavior
Type-only imports (import type X
, or import X
where X is only used as a type) result in incorrect webpack --watch
behavior. When files residing in workspace packages are modified, the importing code does not always get recompiled.
This is a similar issue to #36 and TypeStrong/ts-loader#1138, but that issue has been fixed and the recommendation to use "importsNotUsedAsValues": "preserve"
has been removed in #516. However, issues still arise when using yarn workspaces.
It seems like enabling "importsNotUsedAsValues": "preserve"
and avoiding import type
might be a viable workaround for this issue, but that's not great, because import type
is a core TS feature that should ideally be supported properly.
Expected behavior
Modifying a file in a workspace package should cause webpack to recompile the bundle, even if it's only used via type-only imports.
Steps to reproduce the issue
-
Check out https://github.com/jtbandes/ts-workspaces-repro. This repo uses Yarn workspaces and has two sub-packages under
packages/pkg1
andpackages/pkg2
. The main filesrc/index.ts
imports from these packages. -
Run
yarn install && yarn webpack --watch --progress --mode=development
-
Modify
type Example1
in packages/pkg1/index.ts. Observe that webpack does not recompilesrc/index.ts
nor display new type errors. ❌ -
Modify
function Example2
in packages/pkg2/index.ts. Observe that webpack does recompilesrc/index.ts
and display new type errors (this is not a type-only import). ✅ -
Add
"compilerOptions": { "importsNotUsedAsValues": "preserve" }
to tsconfig.json. Now, observe that changingpkg1/index.ts
does cause webpack to recompile. ✅- Change
import {Example1} from 'pkg1'
toimport type {Example1} from 'pkg1'
in src/index.ts. Observe that changingpkg1/index.ts
again does not result in a recompile. ❌ (This is because"importsNotUsedAsValues": "preserve"
does not affect explicitimport type
imports, which are always removed.)
- Change
Issue reproduction repository
https://github.com/jtbandes/ts-workspaces-repro
Environment
- fork-ts-checker-webpack-plugin: 6.2.6
- typescript: 4.2.4
- ts-loader: 9.1.2
- webpack: 5.37.0
- os: macOS 11.3.1