Effect's Modules
In .vibe files, Effect's entire standard library is already in scope — no boilerplate imports required. Every export of Effect (sleep, retry, timeout, all, forEach, race, log, withSpan, sync, tryPromise, callback, scoped, acquireRelease, runPromise, …), every root module (Console, Option, Stream, Schedule, Clock, Duration, Layer, Schema, …), and every subpath module (HttpRouter, ChildProcess, TestClock, Hex, …) resolves automatically and emits tree-shakeable imports in the compiled JavaScript.
Only platform-specific packages such as @effect/platform-node require explicit imports.
Core package
npm install effect@4.1.1See Installation for vibelang, vibelang-runtime, and platform packages. Root functions (pipe, flow, identity) and core modules (Effect, Layer, Schema, Scope) compile directly to effect/* imports; VibeLang syntax constructs (error, service, match, for concurrent) also use vibelang-runtime.
Using globals and handling name collisions
effect function pauseBeforeRetry() {
const started = try Clock.currentTimeMillis
try sleep(Duration.millis(25))
return started
}
const backoff = Schedule.exponential("50 millis")
// Run in an effect function: try Console.log(Number.isFinite(try pauseBeforeRetry()))
// Output: trueAny local variable or explicit import shadows an implicit global. When an Effect export would clash with a keyword or JavaScript global, qualify it with Effect.:
| Clashes with | Write |
|---|---|
| JavaScript keyword | Effect.try, Effect.catch, Effect.void, Effect.let |
| JavaScript global | Effect.undefined |
| VibeLang keyword | Effect.match, Effect.when, Effect.service, Effect.provide, Effect.interruptible, Effect.uninterruptible |
JavaScript's core globals (Array, String, Number, Boolean, Symbol, BigInt, Function, RegExp, Record) keep their JavaScript meanings. Access Effect's modules of those names via Effect.Array, Effect.String, Effect.Record, or an aliased import:
import { Array as Arr } from "effect"
function firstTwo(values: ReadonlyArray<number>) {
return Arr.take(values, 2)
}
// Run in an effect function: try Console.log(try Effect.try(() => JSON.stringify(firstTwo([1, 2, 3]))))
// Output: [1,2]Note:
Effect.ArrayandEffect.Stringrequire the unshadowed implicitEffect. If you writeimport { Effect } from "effect"or disable implicit globals intsconfig.json("vibe": { "effectGlobals": false, "effectModules": false }), import collision modules separately asimport { Array as Arr } from "effect".
Subpath modules and collision resolution
Subpath modules are in scope too — the compiler emits direct per-file imports (such as effect/encoding/Hex) so your bundle includes only what you touch:
function hexOf(text: string) {
return Hex.encode(new TextEncoder().encode(text))
}
// Run in an effect function: try Console.log(hexOf("hi"))
// Output: 6869When two modules share a name, four rules decide:
- Non-platform JavaScript globals keep their JavaScript meaning.
- A name exported by both root
effectand a subpath requires an explicit import (EK1401). - A name exported by two different subpaths requires an explicit import (
EK1401). - Any explicit import or local declaration shadows the implicit global.
These are the exact resolutions for effect@4.1.6:
| Name | Modules | Without an import |
|---|---|---|
Chat | effect/ai, effect/chat | nothing: import the one you mean (rule 3) |
Event | effect/eventlog | Effect's module; the DOM type keeps its name |
Headers | effect/http | Effect's module; the DOM type keeps its name |
KeyFormat | effect/crypto | Effect's module; the DOM type keeps its name |
Model | effect/ai, effect/schema | nothing: import the one you mean (rule 3) |
Prompt | effect/ai, effect/cli | nothing: import the one you mean (rule 3) |
Response | effect/ai | Effect's module; the DOM type keeps its name |
Transferable | effect/workers | Effect's module; the DOM type keeps its name |
Utils | effect, effect/rpc | nothing: import the one you mean (rule 2) |
Worker | effect/workers | Effect's module; the DOM type keeps its name |
A module's own export
Many Effect modules export a type or service carrying the same name as the module: Option.Option<T>, Chunk.Chunk<T>, FileSystem.FileSystem, Path.Path. Always qualify the member when writing a type or reading a service with try:
| Write | Meaning |
|---|---|
Option.Option<number> | The Option type |
const fs = try FileSystem.FileSystem | Look up the FileSystem service |
try fs.readFileString(path) | Run a method on that implementation |
(try Path.Path).sep | Read a property on the Path implementation |
FileSystem.FileSystem.of(impl) | Type-check an implementation |
effect function readConfig(dir: string) {
const fs = try FileSystem.FileSystem
const path = try Path.Path
return try fs.readFileString(path.join(dir, "config.json"))
}
effect function hasConfig(fs: FileSystem.FileSystem, dir: string) {
const path = try Path.Path
return try fs.exists(path.join(dir, "config.json"))
}
function firstOr(values: Chunk.Chunk<number>, fallback: number): number {
const first: Option.Option<number> = Chunk.head(values)
return Option.getOrElse(first, () => fallback)
}
// Run in an effect function:
// provide Path.layer, FileSystem.layerNoop({ readFileString: effect (path) => `read ${path}` }) {
// try Console.log(try readConfig("/srv"))
// try Console.log(firstOr(Chunk.empty(), 7))
// }
// Output: read /srv/config.json
// Output: 7Modules that export a same-named service:
AddressResolver, Aead, AtomRegistry, ChatHandler, ChatTest, ChildProcessSpawner, Cipher, CircuitBreaker, CliConfig, Clock, ConfigProvider, Console, DatagramSocket, DecisionModel, DevToolsClient, Digest, Dns, EmbeddingModel, EventJournal, EventLog, EventLogEncryption, EventLogRemote, EventLogServerUnencrypted, FileSystem, GraphQLProtocol, HttpClient, HttpPlatform, HttpRouter, HttpServer, HttpServerRequest, IdGenerator, Jwks, K8sHttpClient, Kdf, KeyAgreement, KeyValueStore, KeyWrap, LanguageModel, Mac, McpClient, McpServer, MessageStorage, OtlpSerialization, Password, Path, Persistence, Random, RateLimiter, Reactivity, Redis, ResponseIdTracker, RpcSerialization, RunnerHealth, RunnerStorage, Runners, Scheduler, SecureRandom, Sharding, ShardingConfig, Signature, Socket, SocketServer, SqlClient, Stdio, Terminal, TerminalCapabilities, Tokenizer, Tracer, UserDirectories, WorkflowEngine.
Names with both an Effect namespace (value position) and an ambient DOM type (bare type position — use FileSystem.FileSystem for Effect's type):
Cache, Console, Event, FileSystem, Headers, Iterable, KeyFormat, Record, Request, Response, Scheduler, Transferable, Worker.
Writing reusable operators
Because Effects are first-class values, write generic helpers that accept A!E!R and wrap it with Effect combinators:
effect function withinSecond<A, E, R>(program: A!E!R) {
return try timeout(program, "1 second")
}
effect function example() {
return try withinSecond(effect {
try sleep("10 millis")
return "ready"
})
}
// Run in an effect function: try Console.log(try example())
// Output: readywithinSecond preserves the caller's A, E, and R while adding TimeoutError to E.
Coming from Effect
Drop boilerplate import { Effect, Layer, Schema, ... } from "effect" lines in .vibe files; keep normal imports in .ts files. interrupt and yieldNow are bare Effect values (try interrupt, try yieldNow).
The matching Effect page: effect.website/docs/v4/getting-started/importing-effect