zerodevx / svelte-toast

Simple elegant toast notifications
https://zerodevx.github.io/svelte-toast/
ISC License
796 stars 47 forks source link

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

Open rickexa opened 1 year ago

rickexa commented 1 year ago

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.

hoomp3 commented 1 year ago

@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

rickexa commented 1 year ago

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.

susnick commented 1 year ago

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

zerodevx commented 1 year ago

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

susnick commented 1 year ago

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

zerodevx commented 1 year ago

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

susnick commented 1 year ago

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.

zerodevx commented 1 year ago

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 commented 1 year ago

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

susnick commented 1 year ago

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.

powellnorma commented 1 year ago

Same for me. Uninstalling does not fix issue.

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

powellnorma commented 1 year ago

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?

zerodevx commented 1 year ago

@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).

powellnorma commented 1 year ago

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 commented 1 year ago

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

Iuriy-Budnikov commented 1 year ago

The same issue with vite

zerodevx commented 1 year ago

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
Jaydeep189 commented 1 year ago

@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

Spimy commented 1 year ago

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.

kryptus36 commented 1 year ago

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

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

Iuriy-Budnikov commented 1 year ago

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" }, //... }

wetmarble commented 1 year ago

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

secondl1ght commented 11 months ago

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.

meandrewandyou commented 6 months ago

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