Skip to content

Bug: Incorrect Path Generation for Hoisted Scripts (._astro vs _astro) #167

Open
@Naryalin

Description

Hello,
I've encountered an issue with the @kindspells/astro-shield integration where it generates incorrect paths for hoisted scripts during the build process. Specifically, the integration adds a . prefix to the _astro directory, resulting in paths like ./._astro/hoisted.*.js, causing the following errors during build:

  • With custom assets directory defined in astro.config.mjs:
    build: {
      assets: 'nameOfFolder',
    },
    ENOENT: no such file or directory, open 'C:\path\to\project\dist\.nameOfFolder\hoisted.[hash].js'  
    
  • Without custom directory:
    ENOENT: no such file or directory, open 'C:\path\to\project\dist\._astro\hoisted.[hash].js'  
    

The issue persists even with the default settings. I tested it on a static Astro project, and the same error occurred. It seems like the integration mishandles asset paths when creating integrity hashes for hoisted scripts.

Steps to Reproduce:

  1. Set up an Astro project with @kindspells/astro-shield integration.
  2. Add any inline or hoisted JavaScript, or React components that include JavaScript.
  3. Run astro build.

Expected Behavior:

Hoisted scripts should be placed in the correct _astro directory without the extra . prefix.

Actual Behavior:

The build fails due to incorrect paths like ._astro being used.

Possible Solution:

The issue seems to be caused by an unnecessary . prefix being added when generating paths for hoisted assets. Upon testing, removing this prefix resolves the issue in my project setup. I recommend reviewing the logic responsible for path handling and conditionally applying the . prefix only when necessary, as it may not be universally required for all builds.

This should help maintain compatibility across different configurations.

Thank you for your assistance!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions