histoire icon indicating copy to clipboard operation
histoire copied to clipboard

Import error when using vite base path relative

Open Florent-Bouisset opened this issue 2 years ago • 1 comments

Describe the bug

Hello, thanks for building histoire, love it!

When deploying histoire under a nested public path I set base to empty string https://vitejs.dev/config/shared-options.html#base

// histoire.config.ts
export default defineConfig({
  vite: {
    base: "",
  },

but some ressources are requesting /story/__sandbox.html which doesn't exist in my dist folder resulting in this error: image

Workaround

Creating the folder story manually and copying in it the content of assets fix my issue

# fix-build.sh
mkdir dist/story &&
cp dist/__sandbox.html dist/story/__sandbox.html &&
cp -R dist/assets dist/story/assets

I'm doing that for building: npm run build:story && source fix-build.sh

Reproduction

https://stackblitz.com/edit/histoire-vue3-starter-a7mlkp?file=vite.config.ts

  • build and preview the app
  • open the base button story

System Info

/

Used Package Manager

npm

Validations

Florent-Bouisset avatar Oct 14 '22 11:10 Florent-Bouisset

My base is set to an empty string. I'm deploying to GitLab pages where url is of the following structure: https://deepc.gitlab.io/path/to/project

Histoire root page opens up correctly but then I have links to each story as the following: /./story/src-stories-viewer-story-vue which doesn't correspond to my project url path/to/project. If I open a story the url becomes https://deepc.gitlab.io/story/src-stories-viewer-story-vue and this is incorrect. Refreshing the page now results in error 404. Any way I can fix that?

Update: I switched to "hash" router mode and urls now look #/story/src-stories-viewer-story-vue which fixes my issue. But I still don't understand where does /./ come from with "history" router mode.

additional ref: https://github.com/histoire-dev/histoire/issues/143

desprit avatar Dec 19 '22 18:12 desprit

Histoire should now follow the base from vite configuration. Please reopen if you still have the issue with latest versions of Histoire and Vite.

Akryum avatar Sep 25 '23 09:09 Akryum

I came across this error (on v0.17.2) and originally thought it was the base config too. I was able to fix it by updating the routerMode to hash in histoire.config.

Kane-R-G avatar Oct 18 '23 02:10 Kane-R-G

I came across this error (on v0.17.2) and originally thought it was the base config too. I was able to fix it by updating the routerMethod to hash in histoire.config.

I suppose you mean 'routerMode' => that indeed solved it for me thanks!

mswertz avatar Nov 05 '23 21:11 mswertz

I came across this error (on v0.17.2) and originally thought it was the base config too. I was able to fix it by updating the routerMethod to hash in histoire.config.

I suppose you mean 'routerMode' => that indeed solved it for me thanks!

Apologies it is actually routerMode not routerMethod.

Kane-R-G avatar Nov 05 '23 23:11 Kane-R-G