Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript type exports fail when type is imported from a module #731

Closed
cyberalien opened this issue Aug 22, 2020 · 3 comments
Closed

TypeScript type exports fail when type is imported from a module #731

cyberalien opened this issue Aug 22, 2020 · 3 comments

Comments

@cyberalien
Copy link

Describe the bug

When exporting types in TypeScript that were imported from another library, transpiled file throws error about missing import.

There are no issues when using types from libraries or exporting locally created types, only when exporting types that were imported.

Reproduction

Demo repository: https://github.com/cyberalien/vite-ts-test

Run npm install and npm run dev to test it.

Open it in browser, you should get this error:

SyntaxError: The requested module '/@modules/vue.js' does not provide an export named 'VNode'

This line in src/test.ts is triggering it:

export { VNode };

If that line is removed, everything works fine.

It seem to happen with any exported types that are imported from third party libraries. Local types work fine. Imported types that are part of another local type, also works fine. It fails only when type imported from third party module is exported as is.

System Info

  • required vite version: 1.0.0-rc.4
  • required Operating System: OSX 10.15.6
  • required Node version: 13.12.0
  • Optional:
    • npm/yarn version: npm 6.14.8
    • Installed vue version (from yarn.lock or package-lock.json): 3.0.0-rc.7
    • Installed @vue/compiler-sfc version: 3.0.0-rc.7

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.
vite v1.0.0-rc.4
  vite:config env mode: development +0ms
  vite:config env: {} +1ms
  vite:optimize Hash is consistent. Skipping. Use --force to override. +0ms

  Dev server running at:
  > Local:    http://localhost:3000/
  > Network:  http://169.254.235.123:3000/
  > Network:  http://192.168.0.20:3000/

  vite:server server ready in 446ms. +0ms
  vite:hmr         / imports /src/main.js +0ms
  vite:rewrite (skipped) / +0ms
  vite:rewrite /: serving from cache +0ms
  vite:rewrite (skipped) / +7ms
  vite:rewrite (skipped) /vite/client +11ms
  vite:rewrite /src/main.js: rewriting +2ms
  vite:rewrite     "vue" --> "/@modules/vue.js" +2ms
  vite:hmr         /src/main.js imports /@modules/vue.js +23ms
  vite:rewrite     "./App.vue" --> "/src/App.vue" +0ms
  vite:hmr         /src/main.js imports /src/App.vue +0ms
  vite:rewrite     "./index.css" --> "/src/index.css?import" +1ms
  vite:hmr         /src/main.js imports /src/index.css +1ms
  vite:hmr ws client connected +3ms
  vite:resolve (optimized) vue.js -> node_modules/.vite_opt_cache/vue.js +0ms
  vite:sfc /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/App.vue parsed in 6ms. +0ms
  vite:rewrite /src/App.vue: rewriting +15ms
  vite:resolve (postfix) /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/test -> /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/test.ts +0ms
  vite:rewrite     "./test" --> "/src/test.ts" +0ms
  vite:hmr         /src/App.vue imports /src/test.ts +12ms
  vite:rewrite     "./components/HelloWorld.vue" --> "/src/components/HelloWorld.vue" +1ms
  vite:hmr         /src/App.vue imports /src/components/HelloWorld.vue +1ms
  vite:rewrite /@modules/vue.js: no imports found. +9ms
  vite:sfc /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/App.vue parse cache hit +16ms
  vite:sfc /src/App.vue template compiled in 13ms. +14ms
  vite:rewrite /src/App.vue?type=template: rewriting +21ms
  vite:rewrite     "vue.js" --> "/@modules/vue.js" +0ms
  vite:hmr         /src/App.vue?type=template imports /@modules/vue.js +30ms
  vite:sfc /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/components/HelloWorld.vue parsed in 3ms. +8ms
  vite:rewrite /src/components/HelloWorld.vue: rewriting +67ms
  vite:rewrite     nothing needs rewriting. +0ms
  vite:rewrite /src/test.ts: rewriting +2ms
  vite:rewrite     "vue" --> "/@modules/vue.js" +0ms
  vite:hmr         /src/test.ts imports /@modules/vue.js +69ms
  vite:sfc /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/components/HelloWorld.vue parse cache hit +65ms
  vite:sfc /src/components/HelloWorld.vue template compiled in 10ms. +10ms
  vite:rewrite /src/components/HelloWorld.vue?type=template: rewriting +12ms
  vite:rewrite     "vue.js" --> "/@modules/vue.js" +0ms
  vite:hmr         /src/components/HelloWorld.vue?type=template imports /@modules/vue.js +12ms
  vite:rewrite (skipped) /src/index.css?import +3ms
  vite:rewrite /: serving from cache +702ms
  vite:rewrite (skipped) / +557ms
  vite:rewrite /: serving from cache +9ms
  vite:rewrite (skipped) / +8ms
  vite:rewrite (cached) /src/main.js +19ms
  vite:rewrite (skipped) /vite/client +1ms
  vite:resolve (cached) vue.js -> node_modules/.vite_opt_cache/vue.js +718ms
  vite:rewrite (cached) /@modules/vue.js +10ms
  vite:sfc /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/App.vue parse cache hit +600ms
  vite:rewrite (cached) /src/App.vue +2ms
  vite:hmr ws client connected +601ms
  vite:rewrite (skipped) /src/index.css?import +2ms
  vite:sfc /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/components/HelloWorld.vue parse cache hit +6ms
  vite:rewrite (cached) /src/components/HelloWorld.vue +3ms
  vite:sfc /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/App.vue parse cache hit +1ms
  vite:sfc /src/App.vue template cache hit +0ms
  vite:rewrite (cached) /src/App.vue?type=template +1ms
  vite:rewrite (cached) /src/test.ts +3ms
  vite:sfc /Users/slava/Documents/dev/iconify/_temp/vite-ts-test/src/components/HelloWorld.vue parse cache hit +11ms
  vite:sfc /src/components/HelloWorld.vue template cache hit +0ms
  vite:rewrite (cached) /src/components/HelloWorld.vue?type=template +8ms
@antfu
Copy link
Member

antfu commented Aug 22, 2020

Not sure if it's a bug or limitation of ESbuild, but changing it to either of these will work.

import type { VNode } from 'vue';

export { VNode };
import { VNode } from 'vue';

export type { VNode };

@underfin
Copy link
Member

See evanw/esbuild#341 (comment)

@cyberalien
Copy link
Author

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants