Trouble getting `createEffect` to work outside the browser

Could someone help me get this [1] example from the docs working in node, outside of the brower? I've tried a bunch of stuff, including wrapping it in createRoot() [2] without success. [1] https://docs.solidjs.com/reference/basic-reactivity/create-effect#:~:text=//%20assume%20this%20code,//%20goodbye
createRoot(() => {
const [count, setCount] = createSignal(0);

createEffect(() => console.log("count =", count()));
console.log("hello");
setCount(1);
setCount(2);

queueMicrotask(() => {
console.log("microtask");
setCount(3);
console.log("goodbye");
});
});

// --- overall output: ---
// hello
// microtask
// goodbye
createRoot(() => {
const [count, setCount] = createSignal(0);

createEffect(() => console.log("count =", count()));
console.log("hello");
setCount(1);
setCount(2);

queueMicrotask(() => {
console.log("microtask");
setCount(3);
console.log("goodbye");
});
});

// --- overall output: ---
// hello
// microtask
// goodbye
2 Replies
mdynnl
mdynnl3d ago
node exports are for server usage which doesn't need reactivity so implemented intentionally to be static you can directly import the browser one or use --conditions there's definitely a plan to extract the reactivity core to a separate export but I think the current focus is on better reactivity runtime solid 2.0, it should probably come around after that
peerreynders
peerreynders3d ago
GitHub
GitHub - atk/solid-register
Contribute to atk/solid-register development by creating an account on GitHub.
DEV Community
Discussion of Testing your Solid.js code with jest
So, you have started to write a nice app or library in Solid.js and TypeScript - good choice, by...
GitHub
solid-bookstore-a/package.json at 8afd7a94dbef97e8a6c1591a03a58fa27...
Segregated UI in Action with SolidJS. Contribute to peerreynders/solid-bookstore-a development by creating an account on GitHub.
GitHub
solid-bookstore-a/tests/helpers/index.ts at 8afd7a94dbef97e8a6c1591...
Segregated UI in Action with SolidJS. Contribute to peerreynders/solid-bookstore-a development by creating an account on GitHub.

Did you find this page helpful?