Skip to content

Stopped working with SvelteKit / Vite SSR #6105

@michaelfranzl

Description

@michaelfranzl

Description

I'm using Playcanvas in SvelteKit. This works well up until Playcanvas v1.65.5 but stops working when upgrading to the following release of Playcanvas, which is v1.66.0 (and newer).

Steps to Reproduce

The issue is reproducible with minimal effort.

Using Node.js v20.11.1 LTS, create a new SvelteKit application:

mkdir test
cd test
npm create svelte@latest # interactively accept all defaults
npm i

In the file src/routes/+page.svelte import Playcanvas and instantiate a Vec3:

import * as pc from 'playcanvas';
const vec3 = new pc.Vec3();

Save the file and start the server:

npm run dev

Access the URL printed in the terminal (either using browser or using curl/wget).

Vite immediately crashes with the following messages:

  VITE v5.1.4  ready in 615 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network:  use --host to expose
  ➜  press h + enter to show help
TypeError: __vite_ssr_import_4__.Vec3 is not a constructor
    at /path/to/test/src/routes/+page.svelte:8:12
    at Object.$$render (/path/to/test/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at Object.default (/path/to/test/.svelte-kit/generated/root.svelte:45:41)
    at eval (/path/to/test/src/routes/+layout.svelte:20:218)
    at Object.$$render (/path/to/test/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at /path/to/test/.svelte-kit/generated/root.svelte:44:40
    at $$render (/path/to/test/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at Object.render (/path/toS/test/node_modules/svelte/src/runtime/internal/ssr.js:164:17)
    at Module.render_response (/path/to/test/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:171:29)
    at async Module.render_page (/path/to/test/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:286:10

I tested with Vite v4.5 and current (v5.0) and @sveltejs/kit v1.27 and current (v2.0), with the same results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions