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

adapter-static fallback page not generated when prerender.enabled is false #1588

Closed
seanaye opened this issue May 29, 2021 · 7 comments · Fixed by #2128
Closed

adapter-static fallback page not generated when prerender.enabled is false #1588

seanaye opened this issue May 29, 2021 · 7 comments · Fixed by #2128
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Milestone

Comments

@seanaye
Copy link

seanaye commented May 29, 2021

Describe the bug
Using the adapter static in "SPA" configuration doesn't output any html entry point even though the build completes without errors. All other bundled assets are created as far as i can tell. /build contains

/_app
  |--/assets
  |--/chunks
  |--/pages
  |--...misc.js
_redirects

Logs
Build completes successfully with logs ending in

vite v2.3.3 building SSR bundle for production...
✓ 38 modules transformed.
.svelte-kit/output/server/app.js   396.41kb

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-static
  ✔ done
✨  Done in 3.72s.

To Reproduce
svelte.config.js

import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  // Consult https://github.com/sveltejs/svelte-preprocess
  // for more information about preprocessors
  preprocess: preprocess(),
  kit: {
    // hydrate the <div id="svelte"> element in src/app.html
    target: '#svelte',
    adapter: adapter({
      fallback: "index.html"
    }),
    prerender: {
      enabled: false
    },
    ssr: false,
    vite: {
      ssr: {
        noExternal: ["chart.js"]
      },
    }
  }
};

export default config;

To help us help you, if you've found a bug please consider the following:

  • If possible, we recommend creating a small repo that illustrates the problem.
  • Reproductions should be small, self-contained, correct examples – http://sscce.org.

Occasionally, this won't be possible, and that's fine – we still appreciate you raising the issue. But please understand that Svelte is run by unpaid volunteers in their free time, and issues that follow these instructions will get fixed faster.

Expected behavior
Entrypoint index html should be generated in the root of the build dir

Stacktraces
N/A

Information about your SvelteKit Installation:

Diagnostics

System:
OS: macOS 11.1
CPU: (8) arm64 Apple M1
Memory: 520.03 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.1.0 - ~/.nvm/versions/node/v16.1.0/bin/node
Yarn: 1.22.10 - /opt/homebrew/bin/yarn
npm: 7.11.2 - ~/.nvm/versions/node/v16.1.0/bin/npm
Browsers:
Brave Browser: 91.1.25.68
Firefox: 88.0.1
Safari: 14.0.2
npmPackages:
@sveltejs/kit: ^1.0.0-next.110 => 1.0.0-next.110
svelte: ^3.34.0 => 3.38.2

  • Adapter-Static

Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of SvelteKit entirely?

This is medium high severity, we are unable to deploy our svelte kit SPA, although the dev server works fine

@benmccann benmccann added the bug Something isn't working label May 29, 2021
@benmccann benmccann added this to the 1.0 milestone May 29, 2021
@sidharthv96
Copy link
Contributor

For a workaround, you can change the pages config and it will work.
I've been using it here
https://github.com/sidharthv96/mermaid-live-editor/blob/39d0a634bb4be69f47e194477a0d4ffbccf93f24/svelte.config.js#L16

@NickClark
Copy link

I'm pretty sure that currently, prender has to be set as well. Can't confirm yet, because when I enable prerender, my app doesn't build, despite working in development. Alot of ESM bugs like

Directory import '<path>/node_modules/@apollo/client/core' is not supported resolving ES modules imported from <path>/.svelte-kit/output/server/app.js
Did you mean to import @apollo/client/core/core.cjs.js?

But that's probably more to do with #612 and #503 and apollographql/apollo-client#8218.

If we had a true spa mode, that would also likely fix this.

@cuiqui
Copy link

cuiqui commented Jun 10, 2021

I'm having the same problem as @NickClark. If I turn on prerender a lot of import bugs as he points out:

> Cannot find module '/home/{user}/www/uitt-svelte-kit/node_modules/highcharts/highcharts-more' imported from /home/{user}/www/uitt-svelte-kit/.svelte-kit/output/server/app.js
Did you mean to import highcharts/highcharts-more.js?

Same happens, for instance, with sveltestrap that imports import { createPopper } from '@popperjs/core/dist/esm/popper, without .js.

On the other hand, if I turn off prerendering, then the fallback page is not generated.

@harvey-k
Copy link
Contributor

harvey-k commented Jun 11, 2021

I believe the root cause of this issue is the following check:

if (config.kit.prerender.enabled) {

The following svelte.config.js options provided a workaround of this issue for me:

  ...
  adapter: adapter({
    fallback: 'index.html'
  }),
  ssr: false,
  prerender: {
    // workaround issue 1588 by still having prerendering happen with smallest scope possible 
    // enabled: false
    pages: ['/'],
    crawl: false
  },
  ...

@tjlittle
Copy link

I'm having an issue that may be related. When I build with adapter-static in PWA mode, it correctly builds, then correctly renders, but only on my dev machine. When I copy the project to a build server, the build works, but when adapter static tries to render the fallback page, it fails, and the error message is similar to those described above where it claims it is missing imports.

I've diff-ed the .svelte-kit/output/server/app.js file produced in both environments, and the import that fails is a line of code that is rendered in the app.js file on the build server but not locally. At least in my case the difference appears to be in the code generated by Vite.

@benmccann benmccann added the p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. label Aug 4, 2021
@benmccann
Copy link
Member

Can anyone provide a repo that reproduces this issue?

@harvey-k
Copy link
Contributor

harvey-k commented Aug 8, 2021

@benmccann Adding the following to packages\adapter-static\test\apps\spa\svelte.config.js reproduces this issue.

  prerender: {
    enabled: false
  },
  ssr: false,

PR #2128 makes the tests pass again.

Would the above config changes make a more representative "spa mode" test or would you prefer an separate test app from prerendered and spa be created?

@benmccann benmccann changed the title [email protected] not Generating index.html adapter-static fallback page not generated when prerender.enabled is false Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants