-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
FAQ #581
Comments
Some Vite issues related to the FAQ:
|
Not sure how frequent the question is but it took me a while to discover that Vite's HMR websocket port is not 3000 as advertised, but 24678. Only once I knew that was I able to get my dev server working in a docker container.
|
Related to @tylergannon, I ran into an initial error on startup when using my dotnet backend to proxy the frontend to simplify CORS (https://localhost:5443 => ws://localhost:3001). Adding the following to module.exports = {
kit: {
vite: {
server: {
hmr: {
protocol: 'ws',
port: 3001,
},
}
}
}
|
I feel like a quick guide to Vite's dependency-related options would be a good thing to put in Svelte-Kit's FAQ. The Vite documentation does contain what you need to know, but for a newbie it can feel a bit confusing. Why is there different behavior between I've been doing Javascript for several years and I myself am not 100% clear on some of those questions, certainly not enough to be able to answer newbie questions. Someone new to Javascript is going to feel lost at sea with this stuff. Since Svelte-Kit comes configured with SSR out-of-the-box, I think something in the documentation should include a gentle guide to SSR, the difference between ESM and CJS modules, and what it all means, followed by some suggested troubleshooting steps if you run into the dreaded "require is not defined" error trying to import some NPM package. No need to go into too much detail since it's going to be a document intended for newbies, and you don't want to overwhelm them with too much information, but just something like "Javascript modules have two different formats, CJS that uses 'require' and ESM that uses 'import'. We try to hide the difference from you and make things Just Work™ as much as possible, but you'll occasionally run into trouble with NPM packages you're trying to import. When you do, here are some steps to try." In other words, something like the "How do I fix the error I'm getting trying to include a package?" section in #877 but fleshed out a little more, with a couple sentences to explain the most basic of the concepts and a few different common scenarios: the error message you'll see, the solution that works for that scenario. |
Going to answer some of the questions raised so that it can go into the FAQ.
A lot of what I know about the Vite configs is actually guesswork - we unfortunately don't have a very good answer to this because I literally test it with trial and error. Generally the "algorithm" I use to start with is that I
The difference between prod and dev is because we've explicitly added
Unfortunately for us, it has way more: AMD, UMD, IIFE, etc. Which complicates the above configuration options even further, but CJS and ESM are the main two nowadays, yes.
This should be okay - I can think of several common dependencies people have tried to use in the Discord, like |
@GrygrFlzr thanks for this. Not sure if you saw, but I have a PR pending for the FAQ. Let me know if you have any improvements you'd suggest there: #877. I hadn't mentioned anything about One thing I'm always wondering about is whether this is just how it will always be using Vite or if a portion of these issues are caused by shortcomings in Vite. I linked to vitejs/vite#2579 in the FAQ entry since that seems like a common one. I suspect that there are possibly others that I'm not aware of or that haven't been tracked down yet, but am not basing that off of much besides the fact that no one really understands how these options work which makes me think that's because there's issues preventing them from working consistently. |
The FAQ content has been merged into this repo, but still needs to be published: sveltejs/sites#19 |
Things I see a lot on Discord
jsconfig.json
). can use this as a workaround to fix package imports. e.g.alias: { 'firebase/app': resolve('firebase/app/dist/index.cjs.js') }
dependencies
anddevDependencies
as in ReferenceError: require is not defined #655. or trying toinclude
orexclude
it inoptimizeDeps
)fetch
instead. or if you insist you're probably better off using an ESM-friendly alternative like redaxios. finally, if you still want to use axios itself, try putting it inoptimizeDeps.include
)The text was updated successfully, but these errors were encountered: