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

Build error / TypeError: [vite-plugin-svelte-module] Cannot read properties of undefined (reading 'some') #15284

Closed
imprest opened this issue Feb 13, 2025 · 8 comments · Fixed by #15297
Labels
awaiting submitter needs a reproduction, or clarification

Comments

@imprest
Copy link

imprest commented Feb 13, 2025

Describe the bug

I was trying to integrate svelte with phoenix liveview and initially there were no issues.
However after upgrading from [email protected] -> [email protected]. I get the below error when trying to build.
Downgrading to [email protected] successfully builds.

Reproduction

import Counter from "./pages/Counter.svelte";
import Ledgers from "./pages/Ledgers.svelte";

import { mount, unmount } from "svelte";

const components = {
  Counter, Ledgers
};

function parsedProps(el) {
  const props = el.getAttribute("data-props");
  return props ? JSON.parse(props) : {};
}

const Hooks = {};
Hooks.SvelteHook = {
  mounted() {
    const componentName = this.el.getAttribute("data-name");
    if (!componentName) throw new Error("Component name must be provided");

    const requiredApp = components[componentName];
    if (!requiredApp) {
      throw new Error(
        `Unable to find ${componentName} component. Did you forget to import it into hooks.js?`,
      );
    }

    const pushEvent = (event, data, callback) => {
      this.pushEvent(event, data, callback);
    };

    const handleEvent = (event, callback) => {
      this.handleEvent(event, callback);
    }

    const goto = (href) => {
      this.pushHistoryPatch(href, "push", this.el);
    };

    // eslint-disable-next-line no-undef
    const props = $state({ ...parsedProps(this.el), pushEvent, handleEvent, goto })

    this._instance = mount(requiredApp, {
      target: this.el,
      props
    });
  },

  updated() {
    this._instance.update({ ...parsedProps(this.el) })
  },

  destroyed() {
    if (this._instance) {
      window.addEventListener("phx:page-loading-stop", () => unmount(this._instance), { once: true })
    }
  },
};

export default Hooks;

Logs

error during build:
[vite-plugin-svelte-module] [plugin vite-plugin-svelte-module] Cannot read properties of undefined (reading 'some')
file: /home/hvaria/repos/subledger/assets/src/hooks.svelte.js
TypeError: [plugin vite-plugin-svelte-module] Cannot read properties of undefined (reading 'some')
    at validate_assignment (file:///home/hvaria/repos/subledger/assets/node_modules/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js:45:24)
    at AssignmentExpression (file:///home/hvaria/repos/subledger/assets/node_modules/svelte/src/compiler/phases/2-analyze/visitors/AssignmentExpression.js:11:2)
    at next (file:///home/hvaria/repos/subledger/assets/node_modules/zimmerframe/src/walk.js:107:21)
    at _ (file:///home/hvaria/repos/subledger/assets/node_modules/svelte/src/compiler/phases/2-analyze/index.js:126:3)
    at visit (file:///home/hvaria/repos/subledger/assets/node_modules/zimmerframe/src/walk.js:101:13)
    at Object.next (file:///home/hvaria/repos/subledger/assets/node_modules/zimmerframe/src/walk.js:63:23)
    at ExpressionStatement (file:///home/hvaria/repos/subledger/assets/node_modules/svelte/src/compiler/phases/2-analyze/visitors/ExpressionStatement.js:37:10)
    at next (file:///home/hvaria/repos/subledger/assets/node_modules/zimmerframe/src/walk.js:107:21)
    at _ (file:///home/hvaria/repos/subledger/assets/node_modules/svelte/src/compiler/phases/2-analyze/index.js:126:3)
    at visit (file:///home/hvaria/repos/subledger/assets/node_modules/zimmerframe/src/walk.js:101:13)

System Info

Severity

blocking an upgrade

@imprest imprest changed the title Build error / TypeError: [plugin vite-plugin-svroperties of undefined (reading 'some')elte-module] Cannot read p Build error / TypeError: [vite-plugin-svelte-module] Cannot read properties of undefined (reading 'some') Feb 13, 2025
@voscausa
Copy link

Same here

@webJose
Copy link
Contributor

webJose commented Feb 13, 2025

Adding me here to add some weight. My package for single-spa is affected, as seen in the report linked above.

@brunocalou
Copy link

Same here, but on a SvelteKit project

@dummdidumm
Copy link
Member

Please someone provide a proper reproduction so we can reproduce this.

@dummdidumm dummdidumm added the awaiting submitter needs a reproduction, or clarification label Feb 13, 2025
@imprest
Copy link
Author

imprest commented Feb 13, 2025

Created a repo to recreate the issue. https://github.com/imprest/serr

@webJose
Copy link
Contributor

webJose commented Feb 14, 2025

@dummdidumm , could the unit tests for my project serve as repro?

  1. Clone https://github.com/WJSoftware/wjfe-single-spa-svelte.
  2. Run npm ci.
  3. Run npm up since there are many outdated packages. This will bring svelte v5.20.0 to the table.
  4. Run npm run test. Unit tests should fail.
  5. Run npm i [email protected].
  6. Run npm run test. Unit tests should succeed.

@tomoam
Copy link
Contributor

tomoam commented Feb 14, 2025

Assignments to this.property in a .svelte.js file seem to cause this issue.

Image

It occurs in 5.19.10 and 5.20.0, but with slightly different messages.

It may be due to this change.
https://github.com/sveltejs/svelte/pull/15276/files#diff-650c22803364b65b1d9aa3e102da4dba7e960b0808a9f0d66c199f408a0f1ab7L46-R53

dummdidumm added a commit that referenced this issue Feb 14, 2025
This was the result of a `@ts-expect-error` silencing other type errors, which lead to this creeping in. This changes it so that the object is fully set, so we'll get type errors when new properties need to be added

fixes #15284
@edeleastar
Copy link

edeleastar commented Feb 14, 2025

Hi @dummdidumm

Same here on this project: tutors

To reproduce on build:

This builds successfully, using svelte 5.19.3 - with some warnings.

To produce build error,

[vite-plugin-svelte-module] [plugin vite-plugin-svelte-module] Cannot read properties of undefined (reading 'some')"
t validate_assignment (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js:45:24)
    at AssignmentExpression (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/svelte/src/compiler/phases/2-analyze/visitors/AssignmentExpression.js:11:2)
    at next (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/zimmerframe/src/walk.js:107:21)
    at _ (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/svelte/src/compiler/phases/2-analyze/index.js:126:3)
    at visit (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/zimmerframe/src/walk.js:101:13)
    at Object.next (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/zimmerframe/src/walk.js:63:23)
    at ExpressionStatement (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/svelte/src/compiler/phases/2-analyze/visitors/ExpressionStatement.js:37:10)
    at next (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/zimmerframe/src/walk.js:107:21)
    at _ (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/svelte/src/compiler/phases/2-analyze/index.js:126:3)
    at visit (file:///Users/edeleastar/repos/tutor-sdk/test/tutors-b/node_modules/zimmerframe/src/walk.js:101:13)

Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants