Skip to content
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

isSsrBuild on Vite is false for server build #12585

Closed
khromov opened this issue Aug 17, 2024 · 3 comments
Closed

isSsrBuild on Vite is false for server build #12585

khromov opened this issue Aug 17, 2024 · 3 comments

Comments

@khromov
Copy link

khromov commented Aug 17, 2024

Describe the bug

isSsrBuild is incorrectly false for the server build and client build. This prevents us from applying certain Vite configuration only to server/client builds, blocking for example #12581

Reproduction

https://github.com/khromov/isSsrBuild-bug-repro

Run npm run build, the output is:

isSsrBuild false
vite v5.4.1 building SSR bundle for production...
✓ 79 modules transformed.
isSsrBuild false
vite v5.4.1 building for production...
✓ 61 modules transformed.

Logs

No response

System Info

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M2
    Memory: 36.36 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.1.0 - ~/.nvm/versions/node/v22.1.0/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v22.1.0/bin/npm
    pnpm: 9.7.1 - ~/.nvm/versions/node/v22.1.0/bin/pnpm
    bun: 1.1.4 - ~/.bun/bin/bun
  Browsers:
    Chrome: 127.0.6533.120
    Chrome Canary: 129.0.6621.0
    Safari: 17.6
    Safari Technology Preview: 18.0
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.2.4 
    @sveltejs/kit: ^2.0.0 => 2.5.22 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.1 
    svelte: ^4.2.7 => 4.2.18 
    vite: ^5.0.3 => 5.4.1

Severity

serious, but I can work around it

Additional Information

No response

@Conduitry
Copy link
Member

See also #9544. This might arguably be a duplicate of that.

@khromov
Copy link
Author

khromov commented Aug 17, 2024

@Conduitry Thanks for linking the issue, couldn't find it while searching. It seems like a workaround for now could be to do an inline Vite plugin that looks like below (based on your code). It will then allow you to apply selective configuration (for example for manualChunks) only for the client build:

import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";

export default defineConfig(() => {
  const config = {
    plugins: [
      sveltekit(),
      {
        name: 'ssr-config',
        config(config) {
            if (!config?.build?.ssr) {
              config.build.rollupOptions = config.build.rollupOptions || {};
              config.build.rollupOptions.output = {
                ...config.build.rollupOptions.output,
                manualChunks: (id) => {
                  return "my-app";
                }
              }
            }
            return config;
        },
      },
    ],
  };

  return config;
});

@Conduitry
Copy link
Member

Closing as a duplicate of #9544. It's essentially the same gotcha that needs to be documented.

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants