-
-
Notifications
You must be signed in to change notification settings - Fork 81
Can't initialize state in a Class #231
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
Comments
Do you have another earlier Rollup plugin that's transpiling the class to a function? Please share a complete minimal reproduction, including your Rollup config. |
Had to swap back to stores for now, here is the config import "dotenv/config";
import typescript from "@rollup/plugin-typescript";
import svelte from "rollup-plugin-svelte";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import livereload from "rollup-plugin-livereload";
import { terser } from "rollup-plugin-terser";
import css from "rollup-plugin-css-only";
import copy from "rollup-plugin-copy";
import { sveltePreprocess } from "svelte-preprocess";
const production = !process.argv.includes("--dev");
export default {
input: "src/server/ui/main.js",
output: {
sourcemap: false,
format: "iife",
name: "app",
dir: "build/server/public",
},
plugins: [
typescript({
tsconfig: "src/server/ui/tsconfig.json",
compilerOptions: {
outDir: undefined,
},
}),
svelte({
extensions: [".svelte", ".svelte.js", ".svelte.ts"],
include: "src/server/ui/**/*.{svelte,svelte.js,svelte.ts}",
// needed for typescript support
preprocess: sveltePreprocess(),
compilerOptions: { dev: true, runes: true },
}),
css({ output: "bundle.css" }),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ["svelte"],
exportConditions: ["svelte"],
extensions: [".svelte", ".svelte.js", "svelte.ts"],
}),
commonjs(),
copy({
targets: [
{ src: "src/**/*.html", dest: "build/server/public" },
{ src: "src/**/*.css", dest: "build/server/public" },
],
}),
!production && livereload("build/server/public"),
!production && serve(),
production && terser(),
],
watch: {
clearScreen: false,
},
};
function serve() {
let server;
function toExit() {
if (server) server.kill(0);
}
return {
writeBundle() {
if (server) return;
server = require("child_process").spawn("npm", ["run", "dev:server"], {
stdio: ["ignore", "inherit", "inherit"],
shell: true,
});
process.on("SIGTERM", toExit);
process.on("exit", toExit);
},
};
} |
I'm going to close this given the lack of a minimal reproduction and your comment on the other thread that your app is working now: #230 (comment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The example for initialising state inside a class like described in the docs doesn't work and throws an error
[!] (plugin svelte) CompileError:
$state(...)can only be used as a variable declaration initializer or a class field
The text was updated successfully, but these errors were encountered: