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

SPA mode results in Cannot read properties of null #91

Open
2 tasks done
jzillmann opened this issue Nov 15, 2022 · 0 comments
Open
2 tasks done

SPA mode results in Cannot read properties of null #91

jzillmann opened this issue Nov 15, 2022 · 0 comments

Comments

@jzillmann
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.9.2

Plugin version

3.0.0-beta.27

Node.js version

16.18.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.6

Description

When I enable SPA:

await server.register(FastifyVite, {
  dev: process.argv.includes("--dev"),
  root: import.meta.url,
  spa: true,
});

I'm getting

TypeError: Cannot read properties of null (reading 'routes')
    at Vite.setup (/xxx/node_modules/fastify-vite/mode/development.js:57:35)
    at async Vite.ready (/xxx/node_modules/fastify-vite/index.js:32:55)
    at async file:///xxx/server.js:17:1

Also seems kind of obvious to me that this will always fail looking at development.js:

const loadClient = async () => {
    if (config.spa) {
      return null
    }
...
sync prepareClient (clientModule, scope, config) {
    if (!clientModule) {
      return null
    }
...
return { client, routes: client.routes, handler, errorHandler }

Steps to Reproduce

Enable SPA:

await server.register(FastifyVite, {
  dev: process.argv.includes("--dev"),
  root: import.meta.url,
  spa: true,
});

Expected Behavior

Either enabling SPA should work or there should be a clear instruction on how to set it up.
Would be nice to have a SPA example (preferable in Svelte).

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

1 participant