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

import { applyPolyfills, defineCustomElements } is not working in Vue3 + Vite #3195

Closed
3 tasks done
akhi-ninja opened this issue Dec 24, 2021 · 12 comments
Closed
3 tasks done
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@akhi-ninja
Copy link

Prerequisites

Stencil Version

2.11.0

Current Behavior

Created components with stencil 2.11.0 and publish to npm (https://www.npmjs.com/package/bulma-stencil) , when i am trying to import the component in Vue3 application ( built on vite) not working as per this documentation https://stenciljs.com/docs/vue
But its working when load the module in index.html like this <script type='module' src='node_modules/bulma-stencil/dist/bulma-stencil/bulma-stencil.esm.js'></script>
here is the warning from vite console

image

Expected Behavior

component should load work when we do
import { applyPolyfills, defineCustomElements } from 'bulma-stencil/loader';

Steps to Reproduce

Create a package or use test component which is mentioned in https://stenciljs.com/docs/vue load in vue3 application

Code Reproduction URL

https://github.com/akhi-ninja/bulma-stenciljs

Additional Information

No response

@ionitron-bot ionitron-bot bot added the holiday triage The Stencil team may not respond for an extended period of time label Dec 24, 2021
@ionitron-bot
Copy link

ionitron-bot bot commented Dec 24, 2021

Thanks for the issue! This issue has been labeled as holiday triage. With the winter holidays quickly approaching, much of the Stencil Team will soon be taking time off. During this time, issue triaging and PR review will be delayed until the team begins to return. After this period, we will work to ensure that all new issues are properly triaged and that new PRs are reviewed.
In the meantime, please read our Winter Holiday Triage Guide for information on how to ensure that your issue is triaged correctly.
Thank you!

@rwaskiewicz rwaskiewicz added Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team Bug: Validated This PR or Issue is verified to be a bug within Stencil Feature: Bundling and removed holiday triage The Stencil team may not respond for an extended period of time Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team labels Jan 4, 2022
@rwaskiewicz
Copy link
Member

👋 I think there are two items for the team to look at here to be able to close out this issue:

I've labeled this issue so it gets ingested into our internal issue tracker and to be sure we tackle both of these items. Thanks again!

@jeco123
Copy link

jeco123 commented Mar 10, 2022

Hi guys,

in case you have not already tried, it works when bootstraping vue3 with vue-cli.

@dgateles
Copy link

Awaiting a resolution. Not working with Vite yet.

@rwaskiewicz
Copy link
Member

rwaskiewicz commented May 31, 2022

👋 The bug reported in this issue has been fixed with the v2.16.0 release of Stencil. As a result, I'm going to close this issue. If you believe that the bug still exists, please feel free to open a new ticket. Thanks again!

EDIT: This functionality is gated under a new flag, experimentalimportinjection. Folks wishing to make use of the functionality should enable this flag and recompile their Stencil projects.

@zstundys
Copy link

zstundys commented Jun 2, 2022

Looks like the experimentalImportInjection flag does not work with the vue-output-target guide outlined in the docs :/

image

Would be nice to include Vite-specific guide in the FAQ section :)

Related discussion on vitejs/vite#3326

@jeco123
Copy link

jeco123 commented Jun 2, 2022

from my side everything is ok. I tried react and vue from vite, and vue via the cli.

@zstundys
Copy link

zstundys commented Jun 3, 2022

from my side everything is ok. I tried react and vue from vite, and vue via the cli.

Edit: My apologies, it seems that Vite cached an earlier version of the bundled library with experimentalImportInjection turned off. Restarting the vite server fixed the issue.

What's your configuration when loading the stencil components in Vite Vue project? I thought all that's needed was:

// main.ts
import { ComponentLibrary } from "vue-output-target-components";
app.use(ComponentLibrary);

And then using them in .vue files:

<script setup lang="ts">
import { FdsButton } from "vue-output-target-components";

defineComponent({ components: { FdsButton } }); 
</script>

<template>
  <FdsButton>Hello</FdsButton>
</template>

@jeco123
Copy link

jeco123 commented Jun 3, 2022

// main.js
import { createApp } from 'vue'
import App from './App.vue';

createApp(App).mount('#app')
// app.vue
<script setup>
import { FdsButton } from "vue-output-target-components";
</script>

<template>
  <main>
    <FdsButton>Hello</FdsButton>
  </main>
</template>

@thijsw
Copy link

thijsw commented Jun 3, 2022

I think you also need to setup Vue to recognize the custom elements, like this:

{
  template: {
    compilerOptions: {
      isCustomElement: (tag: string) => tag.startsWith('fds-')
    }
  }
}

See https://www.npmjs.com/package/@vitejs/plugin-vue

@jeco123
Copy link

jeco123 commented Jun 3, 2022

here is my config into stencil.config.ts

    vueOutputTarget({
      componentCorePackage: '@tds/web-components',
      proxiesFile: '../vue/src/proxies.ts',
      includeDefineCustomElements: true,
      componentModels: vueComponentModels,
    }),

@tytusplanck
Copy link

For others debugging this issue, this new flag also fixed issues I was having SvelteKit since it also uses Vite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
Development

No branches or pull requests

7 participants