-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Error including bytemd
dependency
#281
Comments
I don't think this is actually fixed unfortunately. I just upgraded to the latest and am still seeing the same error |
My bad. I assumed this was a pre-bundling bug and only fixed that, looks like the error is coming from loading the module in SSR 🤔 |
TL;DR: Wow this seems like a huge deal than I expected. Through some testing, I realized the issue is that For our case, it happens because However, this isn't an issue in most cases, as long as const debounce = __vite_ssr_import__("lodash.debounce") If not externalized, you get: const debounce = __vite_ssr_import__("/node_modules/lodash.debounce/index.js")
// notice this is the path of the error message of the issue The different path is important as it gets resolved differently by ssrImport. In Svelte's case, this is not externalized because A solution is to externalize Or maybe adjustments can be made in Vite to externalized transitive deps by default. |
replacing the unmaintained lodash.debounce with https://github.com/angus-c/just#just-debounce-it might be a quickfix for bytemd |
There are a lot more deps there that has issues, like |
For lodash.throttle there is just-throttle too. but remark plugins don't always have an alternative that works with esm too i guess. Looks like bytemd is actively working on their package structure, adding an exports field (see history from today) https://github.com/bytedance/bytemd/commits/main/packages/bytemd/package.json |
I don't understand why we're only hitting this with this library. I thought there are lots of Svelte libraries with CJS deps that work. |
I put a
But @bluwy said it wasn't being externalized, so I think perhaps something is going wrong in the Vite code in between where I was looking and where he was looking since I do see it being externalized |
Me too. This looks like something we would have spotted long ago, maybe I'm missing something that's only an issue with bytemd specifically, but it looks to me that it's a general issue 🤔
I tried the same and got I'll try to reproduce this in |
Oh, I think that's because I accidentally had checked in |
Ah yeah with |
This seems to be the issue. It works (well the app is broken for other reasons, but reasons that make more sense) if I strip out the prefix:
Any idea where the code that inserts this might live or what a good solution to it might be? |
I haven't got time to check this deeper today 😅 I think it's Vite that re-using the strings from Re the code block in the comment, the syntax allows no spaces beside the |
Yes, I think that's right. It looks like it's being passed as input to
Yeah, I agree that sounds like a good fix. Do you want to take a stab at that since you implemented it for |
Ah thanks for finding the source. I think a simple fix like the code you shown, and have it applied in the linked code would be enough. I’ve worked a bit on the fix in Vite today but having some hurdles making the tests. Feel free to make the patch too if you’d like, I haven’t put a lot of time into the fix yet. |
Ok, I sent a PR here: vitejs/vite#7154 |
This should be fixed in vite-plugin-svelte 1.0.0-next.40 and Vite 2.9.0-beta.2 |
Describe the bug
Someone on Discord reported that they can't get
bytemd
to work. It looks to me likevite-plugin-svelte
is not detecting thatbytemd
'slodash.debounce
dependency needs to be prebundled. There are also issues reported in thebytemd
repo and on Discord where the error occurs on other dependenciesA couple things I noticed that are off about the packaging:
bytemd
uses.esm.js
and.cjs.js
extensions instead of.mjs
and.cjs
lodash.debounce
has nomain
or any other entry point specified in thepackage.json
Even when I manually edit those I still get the same error.
Reproduction
https://github.com/benmccann/sveltekit-bytemd-bug-reproduction
Logs
System Info
Severity
The top two bugs in the
bytemd
repo are about how the project doesn't work with SvelteKit: https://github.com/bytedance/bytemd/issues/96 and https://github.com/bytedance/bytemd/issues/139The text was updated successfully, but these errors were encountered: