elbywan / wretch

A tiny wrapper built around fetch with an intuitive syntax. :candy:
MIT License
4.83k stars 98 forks source link

Rollup failed to resolve import "wretch/middlewares" #160

Closed sh-ravan closed 1 year ago

sh-ravan commented 1 year ago

I can't get the built-in middleware to work in my Vite project. I have "wretch": "^2.3.0" installed but when I try to build it, it throws an error that says, Rollup failed to resolve import "wretch/middlewares". Looks like it's something to do with the bundler as it can be reproduced in both these places:

https://stackblitz.com/edit/vitejs-vite-cbj21z https://codesandbox.io/p/sandbox/competent-elbakyan-129ojg

elbywan commented 1 year ago

Hey @sh-ravan,

Thanks for reporting the issue 🙏 , I managed to reproduce and this is related to the subpath exports.

I'm looking into it and will publish a fix asap but in the meatime you should be able to import from the nested files instead of the index:

import { retry } from "wretch/middlewares/retry"
sh-ravan commented 1 year ago

Ah, thanks for the quick resolution mate!

Also, heckin cool library. Good riddance axios :P

elbywan commented 1 year ago

Also, heckin cool library. Good riddance axios :P

Haha thanks! 😄

I just released wretch@2.3.1 which should solve the issue, importing from wretch/middlewares and wretch/addons should be working now 🤞.

sh-ravan commented 1 year ago

I just tested it, the new version works perfectly! ⚡