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

onMount Disappearing #9359

Closed
jessiejs opened this issue Oct 28, 2023 · 3 comments
Closed

onMount Disappearing #9359

jessiejs opened this issue Oct 28, 2023 · 3 comments

Comments

@jessiejs
Copy link

jessiejs commented Oct 28, 2023

Describe the bug

onMount calls in Rollup just flat out disappear, and unfortunately I can't do the $$self.$$.on_mount.push workaround as you're not allowed to use $$self.

Reproduction

Unfortunately, I can't reproduce this in the REPL (my exact same component code works!)

rollup.config.mjs

import nodeResolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import { defineConfig } from 'rollup';
import svelte from 'rollup-plugin-svelte';
import preprocess from 'svelte-preprocess';

export default defineConfig({
	input: 'src/main.ts',
	output: {
		file: 'dist/wincfg'
	},
	plugins: [
		nodeResolve(),
		svelte({
			preprocess: preprocess(),
			emitCss: false
		}),
		typescript({
			target: "ES2020"
		}),
	]
})

Component Code

<script lang="ts">
	import { onMount } from "svelte";

	console.log('onmount');
	
	onMount(() => {
		console.log('mounted');
	})
</script>

Output

function instance$2($$self) {
	console.log('onmount');

	return [];
}

Logs

Not seeing any log messages.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz
    Memory: 17.70 GB / 31.80 GB
  Binaries:
    Node: 20.4.0 - ~\scoop\apps\nodejs\current\node.EXE
    Yarn: 1.21.1 - ~\AppData\Local\pnpm\yarn.CMD
    npm: 9.8.1 - ~\scoop\apps\nodejs\current\npm.CMD
    pnpm: 8.6.0 - ~\node_modules\.bin\pnpm.CMD
  Browsers:
    Chrome: 118.0.5993.118
    Edge: Spartan (44.19041.3570.0), Chromium (118.0.2088.69)
    Internet Explorer: 11.0.19041.3570
  npmPackages:
    rollup: ^4.0.2 => 4.0.2
    svelte: ^4.2.2 => 4.2.2

Severity

blocking all usage of svelte

@Conduitry
Copy link
Member

Presumably, however you're bundling this, you're getting the server-side rendering versions of the svelte exports, where onMount is a no-op and gets tree shaken out, instead of the browser versions. We'd need to seem a minimal reproduction, including your build process.

@jessiejs
Copy link
Author

I'm not using SSR.
I made an even simpler reproduction https://github.com/jessiejs/sveltebug (npm build)

@Conduitry
Copy link
Member

You need to pass browser: true to the node-resolve plugin, or it will try to use the server-side versions of any imports. See the example config in the readme of the Svelte Rollup plugin that you're using - https://github.com/sveltejs/rollup-plugin-svelte

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2023
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

No branches or pull requests

2 participants