Skip to content

test: Cannot create proxy with a non-object as target or handler #14633

Closed as not planned
@peterpeterparker

Description

@peterpeterparker

Describe the bug

I'm facing a similar issue with Svelte v5 in testing context to the one someone reported on SO today. The unit test works fine until I add a <style></style> to the component.

As soon as a component contains a style, the following error starts appearing when running npm run test:

FAIL src/tests/lib/components/Back.spec.ts [ src/tests/lib/components/Back.spec.ts ]
TypeError: Error while preprocessing src/lib/components/Back.svelte - Cannot create proxy with a non-object as target or handler
❯ new PartialEnvironment node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:16766:19
❯ preprocessCSS node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:48447:23
❯ node_modules/@sveltejs/vite-plugin-svelte/src/preprocess.js:114:10
❯ style node_modules/@sveltejs/vite-plugin-svelte/src/preprocess.js:77:37
❯ process_single_tag node_modules/svelte/src/compiler/preprocess/index.js:283:21
❯ replace_in_code node_modules/svelte/src/compiler/preprocess/replace_in_code.js:70:23
❯ process_tag node_modules/svelte/src/compiler/preprocess/index.js:300:26
❯ Module.preprocess node_modules/svelte/src/compiler/preprocess/index.js:363:25
❯ compileSvelte node_modules/@sveltejs/vite-plugin-svelte/src/utils/compile.js:85:20

I'm facing an issue in our design kit, which I started using for migrating our existing app to Svelte v5 (PR).

Note that I originally reported the issue to Svelte Testing (here), but since I can reproduce the issue with a Svelte mount, we can rule out that library as the root cause.

Reproduction

git clone https://github.com/peterpeterparker/svelte-vite-testing-library-css
cd svelte-vite-testing-library-css
npm ci
npm run test

Logs

No response

System Info

System:
    OS: macOS 15.1.1
    CPU: (8) arm64 Apple M2
    Memory: 105.69 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.n/bin/node
    Yarn: 1.22.22 - ~/.n/bin/yarn
    npm: 10.9.2 - ~/.n/bin/npm
    pnpm: 9.15.0 - ~/.n/bin/pnpm
  Browsers:
    Brave Browser: 131.1.73.97
    Chrome: 131.0.6778.109
    Safari: 18.1.1
  npmPackages:
    svelte: ^5.0.0 => 5.9.0

Severity

blocking an upgrade

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