Describe the bug
I have a module importing a package, and exporting a type unrelated to this import, and a dummy function just to mark the imported package as used somewhere:
// ReproModule.ts
import * as Invariant form 'ts-invariant'
export type SomeType = { name: string };
export function someFunction() {
throw new Invariant.InvariantError("THIS SHOULD NOT BE BUNDLED")
}
(someFunction is not imported anywhere in the code)
When I import the type using import type { SomeType } from './ReproModule', ts-invariant is not bundled, as expexted.
However, when i change the import to import { type SomeType } from './ReproModule, then the package ts-invariant and all it's deps get bundled in the build, which i believe is not as expected (and was not an issue in Vite 7)
Reproduction
https://github.com/feychenie/repro-vite8-type-only-imports-bundling-issue
Steps to reproduce
- Clone the repo, run
pnpm install, run pnpm build.
- Notice that the type import in
IssueComponent.tsx has this format: import type { SomeType } from ...
- Inspect the build output, or open the vite devtools UI and notice
ts-invariant is not bundled, as expected.
- change the type import in
IssueComponent.tsx to import { type SomeType } from ... and build again.
- notice in the build output or in the devtools ui that the
ts-invariant is not bundled, also tslib
System Info
System:
OS: macOS 26.4
CPU: (10) arm64 Apple M1 Pro
Memory: 69.20 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.13.0 - /Users/feychenie/.nvm/versions/node/v24.13.0/bin/node
npm: 11.6.2 - /Users/feychenie/.nvm/versions/node/v24.13.0/bin/npm
pnpm: 10.12.4 - /Users/feychenie/Library/pnpm/pnpm
Deno: 2.5.6 - /Users/feychenie/.deno/bin/deno
Browsers:
Brave Browser: 146.1.88.138
Chrome: 146.0.7680.178
Firefox: 137.0
Safari: 26.4
npmPackages:
@vitejs/devtools: ^0.1.13 => 0.1.13
@vitejs/plugin-react: ^6.0.1 => 6.0.1
vite: ^8.0.8 => 8.0.8
Used Package Manager
pnpm
Logs
No response
Validations
Describe the bug
I have a module importing a package, and exporting a type unrelated to this import, and a dummy function just to mark the imported package as used somewhere:
(
someFunctionis not imported anywhere in the code)When I import the type using
import type { SomeType } from './ReproModule',ts-invariantis not bundled, as expexted.However, when i change the import to
import { type SomeType } from './ReproModule, then the packagets-invariantand all it's deps get bundled in the build, which i believe is not as expected (and was not an issue in Vite 7)Reproduction
https://github.com/feychenie/repro-vite8-type-only-imports-bundling-issue
Steps to reproduce
pnpm install, runpnpm build.IssueComponent.tsxhas this format:import type { SomeType } from ...ts-invariantis not bundled, as expected.IssueComponent.tsxtoimport { type SomeType } from ...and build again.ts-invariantis not bundled, alsotslibSystem Info
System: OS: macOS 26.4 CPU: (10) arm64 Apple M1 Pro Memory: 69.20 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.13.0 - /Users/feychenie/.nvm/versions/node/v24.13.0/bin/node npm: 11.6.2 - /Users/feychenie/.nvm/versions/node/v24.13.0/bin/npm pnpm: 10.12.4 - /Users/feychenie/Library/pnpm/pnpm Deno: 2.5.6 - /Users/feychenie/.deno/bin/deno Browsers: Brave Browser: 146.1.88.138 Chrome: 146.0.7680.178 Firefox: 137.0 Safari: 26.4 npmPackages: @vitejs/devtools: ^0.1.13 => 0.1.13 @vitejs/plugin-react: ^6.0.1 => 6.0.1 vite: ^8.0.8 => 8.0.8Used Package Manager
pnpm
Logs
No response
Validations