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

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

Open
Naryalin opened this issue Nov 30, 2024 · 0 comments
Open

Comments

@Naryalin
Copy link

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!

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

No branches or pull requests

1 participant