storyblok / storyblok-astro

Astro SDK for Storyblok CMS
MIT License
164 stars 29 forks source link

storyblok-astro requires changes in pnpm to work properly #598

Closed wireless25 closed 8 months ago

wireless25 commented 11 months ago

Expected Behavior

When pnpm is used as package manager storyblok-astro works without additional configuration

Current Behavior

When pnpm is used to install dependencies the package @storyblok/js can not be properly resolved by rollup. I get the following vite error when building:

[vite]: Rollup failed to resolve import "@storyblok/js" from "virtual:storyblok-init".

This happened in my project. To verify it is not a local problem I tried the same with the project you provide on Stackblick.

Steps to Reproduce

  1. Download the code from the Stackblitz project
  2. Install dependencies with pnpm (I use version 8.12)
  3. Build the project

Bildschirmfoto 2023-12-21 um 15 28 00

It is possible to overcome this issue by manually hoisting the storyblok dependencies publicly. In .npmrc it could look like this:

public-hoist-pattern[]=*storyblok*

This is a good workaround, but not straightforward. It would be great if storyblok-astro would work without hoisting the dependencies manually.

wireless25 commented 9 months ago

Hi there, since it's been a while, is there any update on this issue? Were you able to reproduce it? I am happy to add missing information if needed.

schabibi1 commented 9 months ago

Hi @wireless25 I was able to reproduce it. Thanks for providing all the details including a temporary work-around to help us investigate it.

It seems Vite's virtual module convention does not fully work to import modules in JS. I'll investigate more if it can only be detected after the page is loaded.

wireless25 commented 8 months ago

Hey @schabibi1 thx for your reply and the investigation. I am very curious what you will find out.

schabibi1 commented 8 months ago

Hi @wireless25

I investigated, but what we followed on the docs on Vite to force importing the virtual module and its values are not working as they should be. We’ll keep monitoring if there will be an update from the Vite side, and for now, we recommend going with hoisting deps publicly in .npmrc as pnpm suggests on their docs as you found it worked.

I'll close this issue temporary as there is a workqround. But feel free to re-open this issue if the workaround won't work. Or I'll re-open this issue when I find a better solution.