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

Fails to resolve aliases within a sveltekit project #375

Closed
6 tasks done
bhvngt opened this issue Nov 28, 2022 · 4 comments
Closed
6 tasks done

Fails to resolve aliases within a sveltekit project #375

bhvngt opened this issue Nov 28, 2022 · 4 comments
Labels
to triage This issue needs to be triaged

Comments

@bhvngt
Copy link
Contributor

bhvngt commented Nov 28, 2022

Describe the bug

When I try to import using aliases, histoire throws following error

[plugin:vite:import-analysis] Failed to resolve import "$lib/images/github.svg" from "src/lib/components/button/button.svelte". Does the file exist?
20 |  } from "svelte/internal";
21 |  
22 |  import github from "$lib/images/github.svg"; // this throws error
   |                      ^
23 |  const file = "src/lib/components/button/button.svelte";
24 |

It works fine when assets are imported using relative path. It seems to be not picking up the root level tsconfig.json

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-uc6vtd?file=package.json,src%2Flib%2Fcomponents%2Fbutton%2Fbutton.story.svelte,src%2Flib%2Fcomponents%2Fbutton%2Fbutton.svelte&terminal=dev

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @histoire/plugin-svelte: ^0.11.7 => 0.11.7 
    histoire: ^0.11.7 => 0.11.7 
    vite: ^3.1.0 => 3.2.4

Used Package Manager

npm

Validations

@bhvngt bhvngt added the to triage This issue needs to be triaged label Nov 28, 2022
@stackblitz
Copy link

stackblitz bot commented Nov 28, 2022

@simon-amadeus
Copy link

I can confirm!
@bhvngt maybe passing an alias to vite through your config may help:

// histoire.config.ts
import { defineConfig } from 'histoire';
import { HstSvelte } from '@histoire/plugin-svelte';

export default defineConfig({
    plugins: [HstSvelte()],
    setupFile: './histoire.setup.ts',
    vite: {
	resolve: {
	    alias: {
		'$lib': 'src/lib'
	    }
	}
    }
});

@bhvngt
Copy link
Contributor Author

bhvngt commented Nov 30, 2022

Thanks @SzudemJ . I have used this as a workaround and can confirm that it is working out fine for me.

@benmccann
Copy link
Contributor

I hope this will be fixed if we leave SvelteKit's setup plugin in place and remove it's compile plugin. See my comment here: #393 (comment)

@Akryum Akryum closed this as completed Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants