How do I use solid for reactivity without a build step?

I like solid as a frontend library, and I want to use it as a "vanilla" state management library for reactivity. However, I'm confused why running this script without bundling does nothing:
import { createRoot, createSignal, createEffect } from "solid-js";

const root = createRoot(() => {
const [counter, setCounter] = createSignal(0);
createEffect(() => {
console.log(counter());
});

return {
counter,
setCounter,
};
});

root.setCounter(1);
import { createRoot, createSignal, createEffect } from "solid-js";

const root = createRoot(() => {
const [counter, setCounter] = createSignal(0);
createEffect(() => {
console.log(counter());
});

return {
counter,
setCounter,
};
});

root.setCounter(1);
After I bundle (using rollup or bun) and run the script, my effect runs and logs the value of counter, like I expect. How does bundling make reactivity work, even without using babel?
4 Replies
foolswisdom
foolswisdom3mo ago
I assume you are running this in node? The library exports a version with updates disabled (effects are just stubs in this version), for use with server side web. You need to set the appropriate flags to import the browser version I'm not sure what those are exactly, having never done it myself, but it's definitely been discussed arround here before, perhaps you can do a search
vveisard
vveisard3mo ago
Okay, so the root cause is conditional exports of the package.json. With node you can use the --conditions flag. Not sure for bun. I'll see what I can do, thanks!
vveisard
vveisard3mo ago
Found a post in a GitHub related to this, posting in case anyone stumbles across this Discord forum post https://github.com/solidjs/solid/discussions/1065#discussioncomment-2979082
GitHub
Difference between the node and browser environment · solidjs solid...
Hi, please look at this very simple and meaningless code (playground). This code use only regular Solid functions, there is no compilation and code transformations. As you can see, the createMirror...
Jarred
Jarred3mo ago
The —conditions flag was added in Bun v1.0.30, which released about 8 hours ago
Want results from more Discord servers?
Add your server
More Posts
use directive typescript errorWhen i try to use the use: directive i get the error ```Type '{ type: string; placeholder: string; vI have to fetch initial information in a component, how do I do it?const App: Component = () => { const resp = await fetch(...); // show Home component after fDynamically creating resources based on reactive state in Solid Store**What would be the right approach to solve this using solids reactivity? ** I want to achieve the Struggling to understand the correct way to use createResource with a storeI have a global store `export const [dataStore, setDataStore] = createStore({ some: "data"}) `, whicHow do I "protect" routes? I am using @solidjs/routerNow that Outlet is not supported anymore? How do I implement a route guard for nested routes?What are canonical patterns to separate UI from domain logic in SolidJS?I am developing an app that helps guitarists to learn notes. Users learn notes by exercising. The exsolidjs createResource doesn't show error when there was an error i.e 401 Invalid credentialscreateResource data.error always falsesomeone used the plugin postcss-functions ?how to set the visibility of functions in css files. ide shows that there is an unknown function, whHydration Mismatch. Unable to find DOM nodes for hydration keyI'm trying to setup a SolidJS SSR project with Vite, Fastify, and the `@fastify/vite` plugin. I've fsolid primitives storage is bugI can't set value 0 number what is this. Secondly please fix the types in documentation like this