-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
🐛 BUG: Window
is not defined after using lit integration when deployed on netlify
#3126
Comments
Looks like the polyfill(globalThis, {
exclude: 'window document',
}); Is there a particular reason |
The goal of that polyfill code is not to provide a full browser environment. It's really just to provide a few things that are present in some server-runtimes but not others, like |
I think the lit integration does put a |
Hrm thats weird, i was definitely getting that error after adding the lit integration. Ill try to update my dependencies and redeploy tomorrow to see if the problem is still there |
Yeah, this is definitely not working as expected Reproduction:
import { defineConfig } from 'astro/config';
+ import netlify from '@astrojs/netlify';
+ import lit from '@astrojs/lit';
export default defineConfig({
+ integrations: [lit()],
+ adapter: netlify()
});
import { LitElement, html } from 'lit';
export const tagName = 'my-element';
class MyElement extends LitElement {
render() {
return html` <p>Hello world! From my-element</p> `;
}
}
customElements.define(tagName, MyElement);
---
+ import './my-el.js';
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Astro</title>
</head>
<body>
<h1>Astro</h1>
+ <my-element></my-element>
</body>
</html>
|
Ok so I dug a little bit more and it seems like this is a problem in the build. E.g.: if I use a lit component, it imports litelement, which uses some browser apis (like for example some stuff on the window, document, etc). This gets shimmed by lit-ssr. My astro build output (with the netlify adapter) looks like: However, the window shim only gets installed way later in the output bundle (see line nr): So when litelement gets imported at line 4, it'll try to use browser apis that have not been shimmed yet, because that only happens on line 877 You can reproduce this locally by cloning this repro, running the build, and looking at the A fix for this could be to somehow make sure the bundler loads the dom shim module first, but i dont think im knowledgeable enough about astros internals/build process |
Okay, so I've done a little testing myself as well, and the error seems to occur because the import { LitElement, html } from 'lit'; As imports are processed before executing any other code in the
I believe that we could fix this error by exporting Doing our shimming in an import statement would ensure that the shim gets executed before code from other imports. The current approach to inject our shim as regular code into the functions entrypoint bundle doesn't work due to the way imports are handled. CCing @matthewp to get his opinion on that as well. |
I think the larger problem is that imports in your components (e.g. |
Think I have a fix. Since I have a breaking test now, the previous test was passing because the |
What version of
astro
are you using?1.0.0-beta.8
Are you using an SSR adapter? If so, which one?
netlify
What package manager are you using?
npm
What operating system are you using?
mac
Describe the Bug
I added the
lit
integration to my project:Which locally worked fine, but when deployed to netlify, gives me the following error:
Link to Minimal Reproducible Example
astro.new
Participation
The text was updated successfully, but these errors were encountered: