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

Vite: Default import yields more than default export #180

Closed
tobiasdiez opened this issue Nov 17, 2021 · 5 comments
Closed

Vite: Default import yields more than default export #180

tobiasdiez opened this issue Nov 17, 2021 · 5 comments
Labels
bridge bug Something isn't working upstream

Comments

@tobiasdiez
Copy link
Contributor

Environment

  • Operating System: Linux
  • Node Version: v14.18.1
  • Nuxt Version: 2.16.0-27285136.ab1c6cb4
  • Package Manager: yarn@1.22.17
  • Bundler: Webpack
  • User Config: plugins, bridge, target, ssr, buildModules
  • Runtime Modules: -
  • Build Modules: @nuxt/bridge@3.0.0-27286006.a08b435

Reproduction

https://codesandbox.io/s/strange-tree-9fdkz

Describe the bug

VueTailwind defines

    exports.BaseComponent = Component;
    exports.default = plugin;

With bridge.vite = true the import import VueTailwind from "vue-tailwind" (in a plugin) yields the object

{
   BaseCompont: ....
   default: { install: ... }
}

instead of the default plugin { install: ... }. With disabled vite everything works as expected.

As with webpack everything is fine, I suspect there is a problem with bridge instead of with the library VueTailwind.

Additional context

No response

Logs

No response

@ayalon
Copy link

ayalon commented Nov 19, 2021

The issue is, that nuxt vite automatically adds some default exports but does not consider named default exports. I described the issue here:
nuxt/vite#203

@danielroe danielroe added bug Something isn't working upstream and removed pending triage labels Nov 19, 2021
@danielroe danielroe assigned danielroe and unassigned danielroe Nov 19, 2021
@pi0
Copy link
Member

pi0 commented Nov 19, 2021

vue-tailwind@2.5.0 is only exporting a cjs file in umd format. You need to report it to upstream for native esm support.

Here is a proper workaround usage for Vue2/Bridge:

import VueTailwind from "vue-tailwind";
import Vue from "vue";
import { TInput } from "vue-tailwind/dist/components";

const VueTailwindPlugin =
  // @ts-ignore
  VueTailwind.default?.default || VueTailwind.default || VueTailwind;

Vue.use(VueTailwindPlugin, {
  "t-input": {
    component: TInput,
    props: {
      classes: "border-2 block w-full rounded text-gray-800"
      // ...More settings
    }
  }
});

export default {};

Note that nuxtApp.vueApp.use is not right to install Vue2 plugins. It adds overhead to each request.

BTW it seems the upcoming version is being rebranded to variantjs (alfonsobries/vue-tailwind#214)

@pi0 pi0 closed this as completed Nov 19, 2021
@tobiasdiez
Copy link
Contributor Author

Thanks a lot, this worked nicely. Maybe its worthwhile to add this strategy/workaround to the documentation, as I guess there are quite a few libraries that are not yet supporting esm.

By the way, I took the nuxtApp.vueApp.use from https://v3.nuxtjs.org/docs/directory-structure/plugins#vue-plugins. I guess that's the right way with nuxt3 but not with bridge then?

@pi0
Copy link
Member

pi0 commented Nov 19, 2021

Good idea for adding de-default workarounds to esm troubleshoot👍

By the way, I took the nuxtApp.vueApp.use from https://v3.nuxtjs.org/docs/directory-structure/plugins#vue-plugins. I guess that's the right way with nuxt3 but not with bridge then?

Indeed. Docs are following vue3/nuxt3 best practices. We probably need to add some notes to the bridge section about installing vue2 plugins or make vue2App compat better to avoid calling plugin install each time.

@tobiasdiez
Copy link
Contributor Author

Okay, follow up at nuxt/nuxt#12825 and nuxt/framework#2036.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bridge bug Something isn't working upstream
Projects
None yet
Development

No branches or pull requests

4 participants