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

document.createEvent is not a function when build when vue is first in integrations list #4994

Closed
1 task
amiceli opened this issue Oct 5, 2022 · 3 comments · Fixed by #4999
Closed
1 task

Comments

@amiceli
Copy link

amiceli commented Oct 5, 2022

What version of astro are you using?

^1.0.0-rc.3

Are you using an SSR adapter? If so, which one?

none

What package manager are you using?

npm

What operating system are you using?

MacOS

Describe the Bug

I built a project with astro using vue, svelte, solid and lit framework integrations.

When I build project I've following error :

/Users/antoinemiceli/Projects/Github/poke-astro/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js:296
        if (Date.now() > document.createEvent('Event').timeStamp) {
                                  ^

TypeError: document.createEvent is not a function

I contact Astro support on discord and someone (noktasizi) explained me to put client directive on my components client:only="vue".

But it didn't work, and just for test, I try to change integrations order in my astro config file.

Before :

import { defineConfig } from 'astro/config';
import vue from "@astrojs/vue";
import svelte from "@astrojs/svelte";
import lit from "@astrojs/lit";

import solid from "@astrojs/solid-js";

// https://astro.build/config
export default defineConfig({
  integrations: [vue(), svelte(), lit(), solid()]
});

And now :

import { defineConfig } from 'astro/config';
import vue from "@astrojs/vue";
import svelte from "@astrojs/svelte";
import lit from "@astrojs/lit";

import solid from "@astrojs/solid-js";

// https://astro.build/config
export default defineConfig({
  integrations: [svelte(), lit(), vue(), solid()]
});

Just moving vue to third position solved my problem.

But it's weird so I open an issue for this.

I try to make a minimal reproducible example on Stackblitz but I failed.
But you can find all my code on my github project poke-astro.

Link to Minimal Reproducible Example

https://github.com/amiceli/poke-astro

Participation

  • I am willing to submit a pull request for this issue.
@amiceli amiceli changed the title document.createEvent is not a function when build with vue is first in integrations list document.createEvent is not a function when build when vue is first in integrations list Oct 5, 2022
@matthewp
Copy link
Contributor

matthewp commented Oct 6, 2022

Thanks, the reason is that Lit creates a DOM shim that adds the document property to the global. Vue is using the existence of this property to run browser code, which is failing because the shim is only partial.

Reorder fixes your problem but isn't guaranteed to fix all such properties. Some libraries might not be able to run alongside the Lit integration.

I submitted a PR to document this limitation. #4999

@amiceli
Copy link
Author

amiceli commented Oct 6, 2022

Thanks for your answer.

Just for information, if in another project I use only Svelte and Vue.
Does this bug will happen ? Or it's just due to lit ?

@matthewp
Copy link
Contributor

matthewp commented Oct 6, 2022

Due to lit

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

Successfully merging a pull request may close this issue.

2 participants