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

Can't seem to disable SSR compilation #6473

Closed
anicolao opened this issue Aug 31, 2022 · 4 comments
Closed

Can't seem to disable SSR compilation #6473

anicolao opened this issue Aug 31, 2022 · 4 comments

Comments

@anicolao
Copy link

anicolao commented Aug 31, 2022

Describe the bug

Yesterday, I was able to avoid SSR compilation with the following code in hooks.js:

export async function handle({ event, resolve }) {                                                                                                     
    return resolve(event, { ssr: false });                                                                                                             
} 

Then, late last night I updated to next and had to move the prerender default out to +layout.js so I thought I was having a problem relating to #6197 ... but whatever the cause, files that don't compile in a node environment are being compiled as though I have SSR enabled and I think they shouldn't be.

Reproduction

Here is the smallest repro I could make: https://github.com/anicolao/svelte-ssr-bug

  1. clone the repository
  2. run npm run build
  3. observe the error
$ npm run build

> ssr-compilation-bug@0.0.1 build
> vite build

vite v3.1.0-beta.1 building for production...
transforming...
✓ 42 modules transformed.
rendering chunks...
vite v3.1.0-beta.1 building SSR bundle for production...
transforming...
"combineReducers" and "createStore" are imported from external module "@reduxjs/toolkit" but never used in "src/components/auth.ts" and "src/store.ts".
✓ 44 modules transformed.
rendering chunks...
.svelte-kit/output/server/vite-manifest.json                   1.19 KiB
.svelte-kit/output/server/index.js                             64.47 KiB
.svelte-kit/output/server/entries/fallbacks/layout.svelte.js   0.23 KiB
.svelte-kit/output/server/entries/pages/_layout.js             0.05 KiB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js    1.50 KiB
.svelte-kit/output/server/entries/pages/_page.svelte.js        1.75 KiB
.svelte-kit/output/server/chunks/index.js                      3.10 KiB
.svelte-kit/output/server/chunks/hooks.js                      0.11 KiB
file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/.svelte-kit/output/server/entries/pages/_page.svelte.js:2
import { createAction, createReducer, configureStore } from "@reduxjs/toolkit";
                                      ^^^^^^^^^^^^^^
SyntaxError: Named export 'configureStore' not found. The requested module '@reduxjs/toolkit' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@reduxjs/toolkit';
const { createAction, createReducer, configureStore } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async Module.component (file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/.svelte-kit/output/server/nodes/2.js:4:39)
    at async Promise.all (index 1)
    at async render_response (file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/.svelte-kit/output/server/index.js:645:19)
    at async render_page (file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/.svelte-kit/output/server/index.js:1514:12)
    at async resolve (file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/.svelte-kit/output/server/index.js:1876:25)
    at async respond (file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/.svelte-kit/output/server/index.js:1837:22)
file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:50
				throw new Error(format_error(details, config));
				      ^

Error: 500 /
    at file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:50:11
    at save (file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:355:4)
    at visit (file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:232:3)

Node.js v18.7.0
[vite-plugin-svelte-kit] Prerendering failed with code 1
error during build:
Error: Prerendering failed with code 1
    at ChildProcess.<anonymous> (file:///Users/anicolao/projects/svelte/svelte-bug/ssr-compilation-bug/node_modules/@sveltejs/kit/src/exports/vite/index.js:435:15)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)

Logs

No response

System Info

System:
    OS: macOS 12.3.1
    CPU: (8) arm64 Apple M1
    Memory: 313.83 MB / 16.00 GB
    Shell: 5.1.16 - /opt/homebrew/bin/bash
  Binaries:
    Node: 18.7.0 - /opt/homebrew/bin/node
    npm: 8.15.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 104.0.5112.101
    Safari: 15.4
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.70 
    @sveltejs/adapter-static: ^1.0.0-next.39 => 1.0.0-next.40 
    @sveltejs/kit: next => 1.0.0-next.456 
    svelte: ^3.44.0 => 3.49.0 
    vite: ^3.1.0-beta.1 => 3.1.0-beta.1 

Severity

blocking an upgrade

Additional Information

No response

@Rich-Harris
Copy link
Member

Add export const ssr = false to your root +layout.js

@benmccann
Copy link
Member

@anicolao
Copy link
Author

Verified this fix works, might have been nice if there had been an error similar to the one for prerender.

@Rich-Harris
Copy link
Member

whoops — thought we had an error for that case, but the check was buggy. opened #6475

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

3 participants