-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Directory import not supported in build mode #6193
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
Comments
The error is coming from node (see here). You can use Closing this based on the above explanation. Thanks for the write-up in the description, was helpful in tracking down the issue. |
Actually I've already found that SO answer, but that's a different thing from what I asked for: In this case there is no Moreover, I'm not directly calling |
@bluwy can you please reopen it, at least for this reason? |
I see. I thought the error was happening on the build output, instead it's happening on the build process. Can you provide a repro either on github or stackblitz to present the issue? It'll help anyone else to quickly debug your issue too. It might also be worth trying to repro this without sveltekit if possible. |
This comment has been minimized.
This comment has been minimized.
Yes, I'll try to produce a minimal example. In any case, I guess to have found at least a workaround, just reading Kit FAQs. I guess the problem is in the library usage, and most likely Vite itself can do little for it. As you said it boils down to node, so I don't know if it's possible to shim or anything else. The idea is that if your library it's a client-only library, you want to prevent to run at build time, and for this you need not only to avoid calls, but even import (occasionally). import { whatever } from 'myclientonlylib/subfolder'; with: import { onMount } from 'svelte';
onMount(async () => {
const { whatever } = await import('myclientonlylib/subfolder');
} |
🤔I'm not very sure about this issue, I haven't run the code yet. Maybe it's not the same one. But as I checked, that PR does break the |
I made an example project on stackblitz, though maybe not perfectly minimal. Actually, in SvelteKit you need to use |
😂 Sorry, I just figured out the exact problem of the other issue. It's due to a dot in the directory path. |
Thanks for the repro @alecandido. It looks like the issue happens in the adapter step, so it's likely not a Vite bug here. I'll try to dig into this more later before closing this. |
Actually I guess the relevant bit is really that is prerendering everything, but I'm not sure. |
Prerender executes the code in node, that's why you're getting the error from node. I was able to find a workaround. You can set the |
Ok, not the easiest workaround, but still fine. Do you believe this would be relevant to raise for Kit? In any case, many thanks for your effort! |
No problem :) I think the issue might reside in Rollup or Vite of the generated SSR bundle code. But Kit is working as usual here as it's basing off the generated bundle, so no need for an issue there. |
@bluwy still reading the above mentioned FAQ (I'm taking some time to digest), there are another couple of considerations:
|
Yeah perhaps there's an issue with how Kit uses Vite, probably in terms of the build config passed to Vite, but I'll have to find time and isolate it to Vite only to disect the cause of the bug.
|
I had a quick look, and I guess that:
Since I'm completely new the codebase, here I stop, and I'll leave the exploration to you, @bluwy, or someone that is more in touch with the code (unless you can point me out a promising place to start from). |
Forgot to reply 😅 But I've certainly been looking into this from time-to-time. I haven't got it fully figured out, to remove the unused imports in the SSR bundle. Though to be fair, it's more of a workaround for the real issue, that is node and Ultimately, I think it'll benefit if If you're interested in the deeper details for my attempt at fixing this in Vite, currently dependencies that are externalized (not bundled) are kept in the final bundle code as I'm suspecting it's because we didn't tell Rollup that Most importantly, these are all just theories and I haven't actually tested if this would work. Note: This is still not a bug in Vite as it's only working around the real issue. |
Describe the bug
The problem consist in
import
from folders only containing apackage.json
file, whose attributemain
,module
,types
are pointing somewhere else, while running in build mode.I'm sorry that the issue is coming from another framework, unfortunately I'm not much familiar with direct use of Vite, but I'm pretty sure the issue is related to build tools, so it's not specific to the framework.
I was unsure if it's coming from Rollup, or whatever is underlying Vite, but I guess you can help redirect if appropriate.
The full story is the following:
rxdb
events
process
(window.process = window.process || {};
) andglobal
(window.global = window;
), and to make a custom build, adding all RxPlugin and PouchPlugin insideonMount
, in order to do it only inside the browsersvelte-kit dev
svelte-kit build
, then I obtained the error message provided in the logs (for one of the imports, it happens for all of them)package.json
file like the following:https://github.com./pubkey/rxdb/blob/e5731c6953410c02aa66cbab5ac5e44d433b3a58/plugins/core/package.json#L1-L8
containing attributes
main
,jsnext:main
,modules
,types
that are pointing to other filespackage.json
associated, and, e.g., types are completely lost (so typescript hints cannot be used, and the editor complaints it can't find declaration file)This behavior is clearly connect with build and bundling, and so I resorted to looking into Vite.
Moreover, it's different between
svelte-kit dev
andsvelte-kit build
, and sincesvelte-kit
is not a build tool on its own, but it's said to rely on Vite, I guess the issue is connected do Vite.Hope you can help to use the first version of the input, or redirect to the relevant place.
Reproduction
rxdb
System Info
Used Package Manager
pnpm
Logs
Validations
The text was updated successfully, but these errors were encountered: