CloudCannon / bookshop

📚 A component development workflow for static websites.
MIT License
247 stars 21 forks source link

Could not resolve dependency on bookshop:generate #191

Closed michaelroper closed 4 months ago

michaelroper commented 7 months ago

Hey team, I have an Astro site that I am using the astro-icon package to inline some custom SVG icons, and while the site itself builds without a problem, when I try to do bookshop:generate, it throws the below error at the end:

📚 Generating Bookshop integrations

Looking for Bookshop component libraries...
Loading Bookshop from ./src
Loaded 15 components
Creating structures for all components...
Hydrating structures for nested components...
Loaded 1 Bookshop

Looking for output sites...
Found 1 site

Modifying output site at ./.
Connected 0 component thumbnail(s)
Added live editing to 24 pages containing Bookshop components
Skipped 63 pages that didn't contain Bookshop components.
 > node_modules/astro-icon/components/Icon.astro:2:30: 
   error: Could not resolve "virtual:astro-icon" (mark it as external to exclude it from the bundle)
    2 │ import icons, { config } from "virtual:astro-icon";
      ╵                               ~~~~~~~~~~~~~~~~~~~~

Does that sound like something I can solve within my site config, even though the error is coming from the dependency itself? I realise this may not be a bookshop-specific issue, but any pointers on how to resolve would be appreciated.

Tate-CC commented 7 months ago

Hi @michaelroper 👋

It looks like astro-icon integration depends on a Vite plugin in order to build. When bookshop:generate tries to build your components for the browser it runs without that plugin, leading to the error you're seeing.

Unfortunately I don't think there are any great ways to get around this in your config. Bookshop will try and load Vite plugins from your config file when building your components, so if you could find a way to pull the Vite plugin out of astro-icon or write your own plugin that provides a stubbed version of the virtual:astro-icon import that could, in theory, fix your build but may end up being a lot of work.

Tate-CC commented 4 months ago

Hi again @michaelroper, this issue should be fixed in the latest Bookshop release (3.10.0). Bookshop Astro now looks at your site's integrations and tries to pull out any Vite plugins it finds. This is still relatively experimental so your results might vary integration to integration, but in my testing it did work with astro-icon so you should be able to include it alongside Bookshop without issue!

michaelroper commented 4 months ago

Thanks @Tate-CC - I'll check it out when i get a chance!