sveltejs/svelte

`Cannot read properties of undefined (reading 'call')` when using a local npm package

Closed this issue · 2 comments

Describe the bug

Context: I am working on publishing a Svelte component to NPM, and I wanted to test it locally first.

I added a dependency that looks like this: "myrandompackage": "file:../somepath.

Then, I compiled the project using Rollup. It worked fine.

When I opened the page, I got this error: Cannot read properties of undefined (reading 'call'):

Image

Reproduction

Here's the repo: https://github.com/tanin47/bug-svelte-17032

Logs

System Info

$ npx envinfo --system --npmPackages svelte,rollup,webpack --binaries --browsers                                                                                                               6:16PM

  System:
    OS: macOS 15.6.1
    CPU: (14) arm64 Apple M4 Max
    Memory: 235.78 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.18.0 - /Users/tanin/.nvm/versions/node/v22.18.0/bin/node
    npm: 10.9.3 - /Users/tanin/.nvm/versions/node/v22.18.0/bin/npm
  Browsers:
    Chrome: 141.0.7390.123
    Safari: 18.6
  npmPackages:
    rollup: 4.52.5 => 4.52.5
    svelte: 5.41.4 => 5.41.4
    webpack: 5.102.1 => 5.102.1

Severity

blocking all usage of svelte

I had to add dedupe: ['svelte'] to the test project, and it'll work. I'm not sure why.

This works if the test project uses Rollup. If the test project (not the test component) uses webpack, I still can't figure out how to dedupe svelte runtime.

It's a bit weird that the test project has to dedupe svelte runtime explicitly. I feel like some other thing is wrong with my config.

The root cause seems to duplicated svelte runtimes getting bundled.

I notice: if the component uses the same node_modules (by making the component a sub-folder inside the test project), then it works fine.

If the component has its own node_modules, then the error will occur.

I need to publish the npm package locally (using npm pack) instead of doing "myrandompackage": "file:../somepath