svelte-toast icon indicating copy to clipboard operation
svelte-toast copied to clipboard

Failed to resolve entry for package "@zerodevx/svelte-toast"

Open rickexa opened this issue 2 years ago • 24 comments

I've just installed and imported this component in svelte but I get this error:

Internal server error: Failed to resolve entry for package "@zerodevx/svelte-toast". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." specifier in "@zerodevx/svelte-toast" package

simply adding import { SvelteToast } from '@zerodevx/svelte-toast' to +layout.svelte page.

I tried to figure out what that could mean but I'm pretty new to svelte/sveltekit... so I'm writing here to seek for help.

Thanks.

rickexa avatar May 04 '23 13:05 rickexa

@rickexa did you accidentally install it as a dev dependency? I did that and got the same error, had to install with yarn add instead yarn add -D and then restart sveltekit

hoomp3 avatar May 04 '23 15:05 hoomp3

I indeed installed it as a dev dependency since in the readme is specified:

npm i -D @zerodevx/svelte-toast

Anyway I've just tried the normal npm i as you suggest and it seems to work properly.

Thank you very much.

rickexa avatar May 04 '23 16:05 rickexa

Same for me. Uninstalling does not fix issue. I removed all modules and started from scratch. Issue persists.

susnick avatar May 10 '23 10:05 susnick

Perhaps something changed in Svelte-world. @susnick, what's your setup? Are you using SvelteKit?

zerodevx avatar May 10 '23 10:05 zerodevx

I am not using SvelteKit. I use the vite template, svelte-ts for my project.

susnick avatar May 10 '23 11:05 susnick

I just tried on a new svelte-ts instance and it seems to work?

https://stackblitz.com/edit/vitejs-vite-zqx6gs?file=src%2FApp.svelte&terminal=dev

zerodevx avatar May 10 '23 12:05 zerodevx

Yes, I confirmed it works on fresh project. I tried installing on another project I had, and it gave same error, so there must be something else causing the issue. I just switched to using a different lib for toasts, and I have no issues. If you want me to assist troubleshooting for this project, I will help, just point me in direction to go.

susnick avatar May 10 '23 12:05 susnick

I'm not sure how I can help. You're not providing details, and a fresh install on your mentioned setup works, so it's likely something unrelated to this repo.

If you're getting an error like:

Internal server error: Failed to resolve entry for package "@zerodevx/svelte-toast". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." specifier in "@zerodevx/svelte-toast" package

it likely indicates that you're not using a "svelte-aware" bundler setup.

zerodevx avatar May 10 '23 13:05 zerodevx

If you could provide a minimal repro on stackblitz or something, then it'll be much easier to debug.

zerodevx avatar May 10 '23 13:05 zerodevx

So i put my project on stackblitz, and it worked fine. Ill have to spend some time to figure out why it wont work. Thanks for the assist.

susnick avatar May 10 '23 13:05 susnick

Same for me. Uninstalling does not fix issue.

Fwiw, I am facing the same problem, and am also using vite

powellnorma avatar May 11 '23 18:05 powellnorma

it likely indicates that you're not using a "svelte-aware" bundler setup.

What does this mean? What does this package specifiy that would need special handling?

powellnorma avatar May 11 '23 19:05 powellnorma

@powellnorma could you do a minimal repro of the issue in stackblitz?

Fwiw, I am facing the same problem, and am also using vite

Most people are using vite, but there are many flavours, like sveltekit, create-vite, or some other svelte-based starter template.

What does this mean? What does this package specifiy that would need special handling?

Svelte-based template must use tooling that is svelte-aware, meaning when the bundler reads the exports from package.json:

"exports": {
    ".": {
      "types": "./index.d.ts",
      "svelte": "./index.js"
    },
  //...
}

it understands that it's dealing with a svelte component.

Edit: however it seems like multiple users are facing the same issue - perhaps something changed (again) in the Svelte ecosystem in the last week or so, like a breaking PR (happens more often than you think).

zerodevx avatar May 11 '23 19:05 zerodevx

could you do a minimal repro

With the following I am able to reproduce it: https://github.com/powellnorma/toast-problem

Using npm i and npm run dev, I get:

✘ [ERROR] [plugin vite:dep-scan] Failed to resolve entry for package "@zerodevx/svelte-toast". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." entry in "@zerodevx/svelte-toast" package

Thank you for investigating!

powellnorma avatar May 11 '23 19:05 powellnorma

Fyi, after specifying "type": "module", in package.json and updating vite-plugin-svelte + vite it worked

powellnorma avatar May 11 '23 20:05 powellnorma

The same issue with vite

Iuriy-Budnikov avatar May 16 '23 10:05 Iuriy-Budnikov

The same issue with vite

Make sure your dependencies are updated, remove /node_modules and package-lock.json, then reinstall deps.

$ npx npm-check-updates -u
$ rm -rf node_modules
$ rm package-lock.json
$ npm i

zerodevx avatar May 16 '23 10:05 zerodevx

@rickexa did you accidentally install it as a dev dependency? I did that and got the same error, had to install with yarn add instead yarn add -D and then restart sveltekit

This Worked! Thanks

Jaydeep189 avatar Jul 19 '23 03:07 Jaydeep189

I also ran into this issue. However I was able to fix this by simply restarting the vite server so if this was installed while the server was already running, try restarting it. As for installation command, I ran yarn add @zerodevx/svelte-toast.

Spimy avatar Aug 14 '23 16:08 Spimy

I ran into this as well - my solution was to:

pnpm i -D vite@latest @sveltejs/vite-plugin-svelte@latest

kryptus36 avatar Aug 17 '23 22:08 kryptus36

Hey @zerodevx , It looks like an issue with using a turbo repo. It can't resolve a path

"exports": { ".": { "types": "./index.d.ts", "svelte": "./index.js" }, //... }

Iuriy-Budnikov avatar Aug 22 '23 15:08 Iuriy-Budnikov

I was able to resolve this issue by adding "./package.json": "./package.json" to the exports in package.json.

wetmarble avatar Aug 29 '23 15:08 wetmarble

I am also running into this issue and updating deps did not resolve it - I am using the latest version of SvelteKit with the Yarn package manager if that helps.

secondl1ght avatar Oct 19 '23 08:10 secondl1ght

make sure you've updated @sveltejs/vite-plugin-svelte - that solved the issue in my case

meandrewandyou avatar Feb 19 '24 02:02 meandrewandyou