Issue when combining yarn workspaces, type-only imports, webpack --watch
, fork-ts-checker-webpack-plugin
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.
Steps to reproduce:
-
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