vite: No matching export for import typescript interface

Describe the bug

Uncaught SyntaxError: The requested module ‘/app.ts’ does not provide an export named ‘Test’

Reproduction

https://github.com/lake2/vite_bug

System Info

  • vite version: 2
  • Operating System: mac
  • Node version: v15.5.0
  • Package manager (npm/yarn/pnpm) and version: npm 6.14.11

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

This is a wontfix because esbuild transforms files in isolation. If you really want this behavior you need to disable esbuild and use something like @rollup/plugin-typescript. Another way: a.js

export defalut interface list {}

b.js It can be quoted like this

import {defalut as list} from 'a.js'

There is a know issue in Vue with type imports, it should work if you use the import type form

import type { User } from '~/types'

@pingustar let’s avoid commenting on old issues, your question may end up being ignored. Please start a GitHub Discussion or join the chat at Vite Land to ask questions.

I have the same issue. What is the correct way of defining/exporting/importing interfaces @yyx990803?

Do not re-export interface in vite. You can just export it in file A and import it in file B. Don`t try to export it in file B again.

Sorry, for asking again… I seem to do something wrong.

I have a types.ts file

export type User = {
  name: string
  age: number
}

and in my component

<script setup lang="ts">
import { ref } from 'vue'
import { User } from '~/types'

const users = ref<User[]>([])
</script>

Which results in the following error logged to the browser console:

Uncaught SyntaxError: The requested module '/src/types.ts?t=1616447029056' does not provide an export named 'User'

What am I missing?