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

Default export causes lifecycle_outside_component #217

Closed
ESchouten opened this issue Feb 10, 2025 · 4 comments · Fixed by #220
Closed

Default export causes lifecycle_outside_component #217

ESchouten opened this issue Feb 10, 2025 · 4 comments · Fixed by #220

Comments

@ESchouten
Copy link

Describe the bug

Seems like the addition of the default: field to the package.json export in v0.23.3 prevents Runed from being run correctly in consumers of the package in my monorepo that uses Runed indirectly through Bits-UI. It does however work in the package itself. My temporary fix is to add Runed to all consumers.

Reproduction

Create monorepo with a components package which contain Shadcn-Svelte/Bits-UI components and consume this package in another package or app

Logs

https://svelte.dev/e/lifecycle_outside_component
    at Module.lifecycle_outside_component (/node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/shared/errors.js:27:17)
    at get_or_init_context_map (/node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/server/context.js:51:5)
    at setContext (/node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/server/context.js:28:2)
    at Context.set (/node_modules/.pnpm/[email protected][email protected]/node_modules/runed/dist/utilities/context/context.js:63:16)
    at useDialogRoot (/node_modules/.pnpm/[email protected][email protected]/node_modules/bits-ui/dist/bits/dialog/dialog.svelte.js:292:30)
    at Module.Dialog (/node_modules/.pnpm/[email protected][email protected]/node_modules/bits-ui/dist/bits/dialog/components/dialog.svelte:9:15)
    at $$render_inner (/packages/analytics/src/lib/components/CookieWall.svelte:54:32)
    at CookieWall (/packages/analytics/src/lib/components/CookieWall.svelte:174:3)
    at _layout (/apps/boiler/src/routes/+layout.svelte:22:38)
    at Root (/apps/boiler/.svelte-kit/generated/root.svelte:63:3)

System Info

System:
    OS: macOS 15.3
    CPU: (12) arm64 Apple M2 Max
    Memory: 2.93 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.13.1 - /usr/local/bin/node
    npm: 10.9.2 - /usr/local/bin/npm
    pnpm: 9.15.5 - ~/Library/pnpm/.tools/pnpm/9.15.5/bin/pnpm
    bun: 1.2.2 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 132.0.6834.160
    Safari: 18.3

Severity

annoyance

@ESchouten ESchouten changed the title 0.23.3 Default export causes lifecycle_outside_component Feb 13, 2025
@ESchouten ESchouten changed the title Default export causes lifecycle_outside_component Default export causes lifecycle_outside_component Feb 13, 2025
@Magnus-Ignitic
Copy link

Magnus-Ignitic commented Feb 23, 2025

I am still getting the same exact error with the latest bits-ui and runed releases, but have failed to pinpoint the root cause (see error below). For me this only happens with Vite 6 btw.

@ESchouten How exactly do you add runed to all consumers, simply importing it like so:

import * as runed from 'runed';

and does it work for you with runed 0.23.4?

Uncaught Error Error: https://svelte.dev/e/lifecycle_outside_component
    at lifecycle_outside_component (.../node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/shared/errors.js:32:9)
    at get_or_init_context_map (.../node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/server/context.js:51:5)
    at setContext (.../node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/server/context.js:28:2)
    at set (.../node_modules/.pnpm/[email protected][email protected]/node_modules/runed/dist/utilities/context/context.js:63:16)
    at useTooltipProvider (.../node_modules/.pnpm/[email protected][email protected]/node_modules/bits-ui/dist/bits/tooltip/tooltip.svelte.js:275:35)
    at Tooltip_provider (.../node_modules/.pnpm/[email protected][email protected]/node_modules/bits-ui/dist/bits/tooltip/components/tooltip-provider.svelte:16:2)

@ESchouten
Copy link
Author

@Magnus-Ignitic haven't updated yet, will do soon. I don't import Runed in my consumers, I just included Runed in the consumers package.json files.

@Magnus-Ignitic
Copy link

I see. I'm already using Runed directly in the consumer packages so something else the issue for me then 🤔

Still curious to know if 0.23.4 works for you once you update :)

@Magnus-Ignitic
Copy link

I found my culprit which is the following lines in vite.config.js:

  resolve: {
    // The default would be [ 'svelte', 'node' ]
    // as set by vite-plugin-svelte and vitest.
    // This sets [ 'browser', 'svelte', 'node' ]
    conditions: mode === 'test' ? ['browser'] : [],
  },

used to make tests work.

Reproduction

https://www.sveltelab.dev/3aiwrh7bswdkxp6

Solution

Following the instructions on how to set up the Svelte testing library below, there is no apparent need to include resolve in the setup, simply removing it seems to work. In Vite 5 things were done magically it seems, but if using resolve in Vite 6 you need to correctly set the defaults yourself: ['module', 'browser', 'development|production']

Related links

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

Successfully merging a pull request may close this issue.

2 participants