Skip to content

import { type A } from './types' triggers error during build #514

Open
@Deckluhm

Description

Related plugins

Describe the bug

I recently upgraded an app I'm working on:

  • vite from 5.3.3 to 6.0.7
  • @vitejs/plugin-vue from 5.0.5 to 5.2.1

And the following code:

import { type A } from './types'

raised an error during build (the build-only phase, not the type-check one):

❯ npm run build

> vite-vue-typescript-starter@0.0.0 build
> vue-tsc -b && vite build

vite v6.0.9 building for production...
✓ 17 modules transformed.
x Build failed in 1.16s
error during build:
Could not resolve "./types" from "src/App.vue?vue&type=script&setup=true&lang.ts"
file: /home/projects/vitejs-vite-xaslukcp/src/App.vue?vue&type=script&setup=true&lang.ts
    at getRollupError (file:///home/projects/vitejs-vite-xaslukcp/node_modules/rollup/dist/es/shared/parseAst.js:558:41)
    at error (file:///home/projects/vitejs-vite-xaslukcp/node_modules/rollup/dist/es/shared/parseAst.js:554:42)
    at handleInvalidResolvedId (file:///home/projects/vitejs-vite-xaslukcp/node_modules/rollup/dist/es/shared/node-entry.js:20239:37)
    at getResolveStaticDependencyPromises/< (file:///home/projects/vitejs-vite-xaslukcp/node_modules/rollup/dist/es/shared/node-entry.js:20199:26)

Reproduction

https://stackblitz.com/edit/vitejs-vite-xaslukcp

Steps to reproduce

  1. Open reproduction
  2. Run npm run build in terminal

You can then change the import on line 3 of src/App.vue:

- import { type ID } from './types';
+ import type { ID } from './types';

and run npm run build again to make it work.

According to https://www.typescriptlang.org/docs/handbook/2/modules.html#import-type, both syntaxes are valid.

Also I don't know if it helps but the following Vanilla Vite project doesn't have the issue so I guess that's a problem with the Vue plugin.

System Info

System:
  OS: Linux 5.15 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
  CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600KF
  Memory: 14.53 GB / 15.53 GB
  Container: Yes
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 23.6.0 - ~/.nvm/versions/node/v23.6.0/bin/node
  npm: 10.9.2 - ~/.nvm/versions/node/v23.6.0/bin/npm
  bun: 1.1.45 - ~/.bun/bin/bun

Used Package Manager

npm (in reproduction), bun (locally)

Validations

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions