Loomguides

Package compatibility

The automatic source redirect, the built-in adapters, and the `shims` option for everything else.

Every package your roblox-ts code imports needs something a browser can run. Most packages work with no setup. This page covers the few that don’t, and how to fix them with shims.

The automatic case

A normal roblox-ts package points "main" at compiled Luau:

{ "main": "out/init.luau", "types": "out/index.d.ts" }

Loom sees the .luau main and loads the package’s TypeScript source from src/index.ts instead. A missing out/ folder doesn’t matter. @rbxts/* specifiers are the exception: they go through the alias table.

The case that needs help

A declaration-only package ships a Luau runtime and .d.ts files, but no TypeScript implementation:

{ "main": "src/init.lua", "types": "src/index.d.ts" }

Luau can’t run in a browser, and .d.ts files are only types. The package needs a browser module in its place. Loom ships one for some packages. For the rest, you write a shim.

What loom ships

SpecifierStand-in
@rbxts/reactThe full browser-meaningful runtime surface of @rbxts/react@17.3.7-ts.2, forwarding standard React by identity to loom’s own React 18.
@rbxts/react-robloxcreateRoot, createBlockingRoot, createLegacyRoot, createPortal, act, version, plus the namespace as a default export, matching upstream’s export = typings.
@rbxts/servicesLoom’s service singletons, the same objects game.GetService(...) returns.
@rbxts/vide@loom-dev/vide, the signals adapter.
@rbxts/ui-labsThe non-story Environment. Root specifier only.
@rbxts/ripple @rbxts/react-rippleA port of the published spring, tween and motion implementation.

Previewed code gets the roblox-ts Promise (evaera’s) as a module-scope binding, not a global. The page’s own Promise is left alone, since the bundler, React and loom depend on it.

React-Lua semantics the stand-in keeps

@rbxts/react behaves like React-Lua, not React DOM, in four ways your code may rely on:

  • A detached ref is undefined, not null, for useRef, createRef and callback refs. ref.current !== undefined checks work as in Roblox.
  • A host instance is named after its key, or the nearest keyed ancestor’s. <frame key="Content"> makes FindFirstChild("Content") find it.
  • cloneElement accepts a Map as its config, as upstream accepts any table.
  • A table cast to Map behaves like one. .get, .set, .has and .delete on a plain table work, and str.match(luaPattern) uses Lua patterns, not JavaScript RegExp.

@rbxts/ui-labs

The root import works with no setup:

import { Environment } from "@rbxts/ui-labs";

Loom behaves the way UI Labs does when your code runs outside a story:

  • Environment.IsStory() returns false.
  • Environment.InputListener is undefined. It only exists in stories.
  • Environment.UserInput is loom’s UserInputService, the same object game.GetService(...) returns.
  • Unmount, Reload, CreateSnapshot and SetStoryHolder do nothing, and GetJanitor() returns undefined, so cleanup code doesn’t fail.

So the usual input guard picks loom’s service:

import { Environment } from "@rbxts/ui-labs";
import { UserInputService } from "@rbxts/services";
export const InputService = Environment.IsStory()
? Environment.InputListener
: UserInputService;

@rbxts/ripple and @rbxts/react-ripple

Both root imports work with no setup:

import { config, useSpring } from "@rbxts/react-ripple";
function AnimatedButton() {
const [offset, spring] = useSpring(0, config.stiff);
return (
<textbutton
Size={offset.map((value) => UDim2.fromOffset(200 + value, 50 + value))}
Event={{
MouseEnter: () => spring.setGoal(10),
MouseLeave: () => spring.setGoal(0),
}}
/>
);
}

Loom ports Ripple’s Luau source, so a component animates as it does in Roblox. See Animation for the full API.

shims

For any other package loom can’t run, point it at a browser module you write:

vite.config.ts
loomPreview({
shims: { "@rbxts/example": "./loom-shims/example.ts" },
});
  • A target is an absolute path, a path relative to the project root, or a bare package id.
  • Matching is exact. @rbxts/example doesn’t cover @rbxts/example/controls, so list subpaths separately.
  • Shims take priority over loom’s own stand-ins, so you can override those too.

Every entry point takes the option:

Entry pointWhere shims goes
loomPreview()The plugin options object.
loom previewloom.config.ts. loom build doesn’t read that file; build with vite build and loomPreview() instead.
createGalleryServer / buildGalleryThe loom-dev/embed options object.
withLoomGallery()The loom-dev/next options object (paths relative to root).
loom.config.ts
export default {
targets: "src/scenes",
shims: { "@rbxts/example": "./loom-shims/example.ts" },
};

Writing a shim

Cover only the part of the package your code uses. Import loom’s modules the way app code does. @rbxts/services gives you loom’s singletons, so a shim can hand back the same object game.GetService(...) returns:

loom-shims/example.ts
import { UserInputService } from "@rbxts/services";
export const listener = UserInputService;

Never construct a second service. Leave everything else out. An import you didn’t shim then fails loudly instead of behaving differently from Studio.

The error you are trying to avoid

A package loom can’t run, with no shim, fails with this:

[loom] Package "@rbxts/example" only provides a Lua/Luau runtime ("src/init.lua") and cannot run in the browser.
Imported by /project/src/app.ts
Provide a browser-compatible replacement with:
loomPreview({
shims: {
"@rbxts/example": "./loom-shims/example.ts",
},
});
The same `shims` option exists on loom.config.ts, `loom-dev/embed` and withLoomGallery().

Without that check, you would see Vite’s Failed to resolve entry for package, or, in a build only, Rollup trying to parse Luau as JavaScript:

RollupError:
../node_modules/@rbxts/example/src/init.luau (1:6):
Expected ';', '}' or <eof>

Both mean the same thing. The fix is a shim.