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

Cannot find module when importing #1340

Closed
NazCodeland opened this issue Apr 19, 2023 · 5 comments
Closed

Cannot find module when importing #1340

NazCodeland opened this issue Apr 19, 2023 · 5 comments

Comments

@NazCodeland
Copy link

NazCodeland commented Apr 19, 2023

Hey, my project is using Svelte/SvelteKit and when I import Giscus;

import Giscus from '@giscus/svelte';

I am getting the warning that Cannot find module '@giscus/svelte' or its corresponding type declarations.js(2307)
however, I can import it like this import Giscus from 'C:/Users/o0/source/projects/mine/NazCodeLandSvelteKit/node_modules/@giscus/svelte/package/Giscus.svelte'; but I believe this is causing an issue for me when I try to deploy my project using Vercel

Error: [vite]: Rollup failed to resolve import "C:/Users/o0/source/projects/mine/NazCodeLandSvelteKit/node_modules/@giscus/svelte/package/Giscus.svelte" from "/vercel/path0/src/routes/(app)/blog/[slug]/+page.svelte".
--
02:01:39.154 | This is most likely unintended because it can break your application at runtime.
02:01:39.154 | If you do want to externalize this module explicitly add it to
02:01:39.154 | `build.rollupOptions.external`
@NazCodeland
Copy link
Author

Well, thanks to ChatGPT I got it working by adding this to my vite.config.js js resolve: { alias: [ { find: '@giscus/svelte', replacement: 'C:/Users/o0/source/projects/mine/NazCodeLandSvelteKit/node_modules/@giscus/svelte/package/Giscus.svelte' } ] }

@calummm
Copy link

calummm commented Apr 26, 2023

I am also getting the Cannot find module '@giscus/svelte' or its corresponding type declarations.js warning in VsCode and svelte-check output but the application builds correctly which leads me to believe the issue is with the type declaration perhaps?

I do not believe an alias replacement is the best solution in this case and recommend reopening this issue.

This is for a sveltejs/[email protected] application built on linux

@NazCodeland NazCodeland reopened this Apr 30, 2023
@Feuerhamster
Copy link

Same issue here.
I got the error dissapear by doing
import Giscus from "@giscus/svelte/package/Giscus.svelte";
instead of
import Giscus from "@giscus/svelte";

I think that this has something todo with the module resolution of typescript.
It works fine if I set "moduleResolution": "NodeNext" in the tsconfig compiler options but then all the sveltekit aliases wont work.

@laymonage
Copy link
Member

Should be fixed in v2.3.0, please update and confirm. Thanks!

@calummm
Copy link

calummm commented Jul 3, 2023

Working now correctly. Thank you

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

4 participants