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

binary asset formats (e.g. png) are getting corrupted when bundled with new URL + import.meta.url #1409

Closed
thescientist13 opened this issue Feb 8, 2025 · 0 comments · Fixed by #1411
Assignees
Labels
bug Something isn't working CLI v0.31.1
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Feb 8, 2025

What happened?

Noticed as part of debugging #1408 (comment) that certain bundled asset were not loading correctly after running the build command.
Image

Steps to reproduce

  1. Have a binary asset type (e.g. .png, .svg)
  2. Reference it in a component using new URL + import.meta.url
const template = document.createElement('template');

export default class HeaderComponent extends HTMLElement {
  #logo = new URL("../../assets/greenwood-logo.png", import.meta.url);

  connectedCallback() {
    if (!this.shadowRoot) {
      template.innerHTML = `
        <header class="header">
          <a href="/">
            <img src="${this.#logo.pathname.replace(window.location.pathname, "/")}" alt="Greenwood Logo"/>
            <h4>My Blog</h4>
          </a>
        </header>
      `;
      
      this.attachShadow({ mode: 'open' });
      this.shadowRoot.appendChild(template.content.cloneNode(true));
    }
  }
}

customElements.define('app-header', HeaderComponent);

Repro here - https://github.com/ProjectEvergreen/greenwood-getting-started/compare/1408-debug-new-url-import-meta?expand=1

Environment

  • Greenwood v0.31.0
  • Node v22

Additional Context

Looking at the generated output, it looks like the file is getting corrupted somehow, with starting source size of 7KB, and ending up as 12KB?
Image

Plus VSCode can't open it
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CLI v0.31.1
Projects
1 participant