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
| Specifier | Stand-in |
|---|---|
@rbxts/react | The 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-roblox | createRoot, createBlockingRoot, createLegacyRoot, createPortal, act, version, plus the namespace as a default export, matching upstream’s export = typings. |
@rbxts/services | Loom’s service singletons, the same objects game.GetService(...) returns. |
@rbxts/vide | @loom-dev/vide, the signals adapter. |
@rbxts/ui-labs | The non-story Environment. Root specifier only. |
@rbxts/ripple @rbxts/react-ripple | A 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, notnull, foruseRef,createRefand callback refs.ref.current !== undefinedchecks work as in Roblox. - A host instance is named after its
key, or the nearest keyed ancestor’s.<frame key="Content">makesFindFirstChild("Content")find it. cloneElementaccepts aMapas its config, as upstream accepts any table.- A table cast to
Mapbehaves like one..get,.set,.hasand.deleteon a plain table work, andstr.match(luaPattern)uses Lua patterns, not JavaScriptRegExp.
@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()returnsfalse.Environment.InputListenerisundefined. It only exists in stories.Environment.UserInputis loom’sUserInputService, the same objectgame.GetService(...)returns.Unmount,Reload,CreateSnapshotandSetStoryHolderdo nothing, andGetJanitor()returnsundefined, 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;Story creators, controls, snapshots and the plugin APIs aren’t emulated, and neither are subpaths. Importing one fails with a normal missing-export error.
@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:
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/exampledoesn’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 point | Where shims goes |
|---|---|
loomPreview() | The plugin options object. |
loom preview | loom.config.ts. loom build doesn’t read that file; build with vite build and loomPreview() instead. |
createGalleryServer / buildGallery | The loom-dev/embed options object. |
withLoomGallery() | The loom-dev/next options object (paths relative to root). |
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:
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.
The dev server only loads the scenes you open, but loom build loads them all. A package used only
by a scene you never opened fails the build even though dev works.