Deno 1.x to 2.x Migration Guide
This document contains guidance for migrating from Deno version 1.x to the upcoming Deno 2.0.
Deno 2.0 is under active development - these API changes and recommendations will continue to be updated until the launch of 2.0.
API changes and deprecations
The following APIs have changed or deprecated between Deno 1.x and 2.x, and will be removed in 2.x - guidance for migrating to a newer set of APIs is provided for each impacted API below.
Deno.Buffer
Use Buffer
from the Standard
Library instead.
+ import { Buffer } from "jsr:@std/io/buffer";
- const buffer = new Deno.Buffer();
+ const buffer = new Buffer();
See deno#9795 for details.
Deno.Closer
Use Closer from the Standard Library instead.
+ import type { Closer } from "jsr:@std/io/types";
- function foo(closer: Deno.Closer) {
+ function foo(closer: Closer) {
...
}
See deno#9795 for details.
Deno.close()
Use the .close()
method on the resource instead.
- Deno.close(file.rid);
+ file.close();
- Deno.close(conn.rid);
+ conn.close();
See the Deno 1.40 blog post for details.
Deno.Conn.rid
Use Deno.Conn
instance methods instead.
- await Deno.read(conn.rid, buffer);
+ await conn.read(buffer);
- await Deno.write(conn.rid, data);
+ await conn.write(data);
- Deno.close(conn.rid);
+ conn.close();
- await Deno.shutdown(conn.rid);
+ await conn.closeWrite();
See the Deno 1.40 blog post for details.
Deno.ListenTlsOptions.certChain
Use
Deno.ConnectTlsOptions.cert
instead.
const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
using conn = await Deno.connectTls({
hostname: "192.0.2.1",
port: 80,
caCerts: [caCert],
- certChain: Deno.readTextFileSync("./server.crt"),
+ cert: Deno.readTextFileSync("./server.crt"),
key: Deno.readTextFileSync("./server.key"),
});
See deno#22274 for details.
Deno.ConnectTlsOptions.certFile
Use
Deno.ConnectTlsOptions.cert
instead.
const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
using conn = await Deno.connectTls({
hostname: "192.0.2.1",
port: 80,
caCerts: [caCert],
- certFile: "./server.crt",
+ cert: Deno.readTextFileSync("./server.crt"),
key: Deno.readTextFileSync("./server.key"),
});
See deno#22274 for details.
Deno.ConnectTlsOptions.privateKey
Use
Deno.ConnectTlsOptions.key
instead.
const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
using conn = await Deno.connectTls({
hostname: "192.0.2.1",
port: 80,
caCerts: [caCert],
cert: Deno.readTextFileSync("./server.crt"),
- keyFile: "./server.key",
+ key: Deno.readTextFileSync("./server.key"),
});
See deno#22274 for details.
Deno.copy()
Use copy()
from the Standard Library
instead.
+ import { copy } from "jsr:@std/io/copy";
...
- await Deno.copy(reader, writer);
+ await copy(reader, writer);
See deno#9795 for details.
Deno.customInspect
Use Symbol.for("Deno.customInspect")
instead.
class Foo {
- [Deno.customInspect]() {
+ [Symbol.for("Deno.customInspect")] {
}
}
See deno#9294 for details.
Deno.File
Use Deno.FsFile
instead.
- function foo(file: Deno.File) {
+ function foo(file: Deno.FsFile) {
...
}
See deno#13661 for details.
Deno.flock()
Use Deno.FsFile.lock()
instead.
- await Deno.flock(file.rid);
+ await file.lock();
See deno#22178 for details.
Deno.flockSync()
Use
Deno.FsFile.lockSync()
instead.
- Deno.flockSync(file.rid);
+ file.lockSync();
See deno#22178 for details.
Deno.fstatSync()
Use
Deno.FsFile.statSync()
instead.
- const fileInfo = Deno.fstatSync(file.rid);
+ const fileInfo = file.statSync();
See the Deno 1.40 blog post for details.
Deno.fstat()
Use Deno.FsFile.stat()
instead.
- const fileInfo = await Deno.fstat(file.rid);
+ const fileInfo = await file.stat();
See the Deno 1.40 blog post for details.
Deno.FsWatcher.rid
Use Deno.FsWatcher
instance methods
instead.
- Deno.close(watcher.rid);
+ watcher.close();
See Deno 1.40 blog post for details.
Deno.ftruncateSync()
Use
Deno.FsFile.truncateSync()
instead.
- Deno.ftruncateSync(file.rid, 7);
+ file.truncateSync(7);
See the Deno 1.40 blog post for details.
Deno.ftruncate()
Use
Deno.FsFile.truncate()
instead.
- await Deno.ftruncate(file.rid, 7);
+ await file.truncate(7);
See the Deno 1.40 blog post for details.
Deno.funlock()
Use
Deno.FsFile.unlock()
instead.
- await Deno.funlock(file.rid);
+ await file.unlock();
See deno#22178 for details.
Deno.funlockSync()
Use
Deno.FsFile.unlockSync()
instead.
- Deno.funlockSync(file.rid);
+ file.unlockSync();
See deno#22178 for details.
Deno.futimeSync()
Use
Deno.FsFile.utimeSync()
instead.
- Deno.futimeSync(file.rid, 1556495550, new Date());
+ file.utimeSync(1556495550, new Date());
See the Deno 1.40 blog post for details.
Deno.futime()
Use
Deno.FsFile.utime()
instead.
- await Deno.futime(file.rid, 1556495550, new Date());
+ await file.utime(1556495550, new Date());
See the Deno 1.40 blog post for details.
Deno.isatty()
Use Deno.FsFile.isTerminal()
, Deno.stdin.isTerminal()
,
Deno.stdout.isTerminal()
or Deno.stderr.isTerminal()
instead.
- Deno.isatty(file.rid);
+ file.isTerminal();
- Deno.isatty(Deno.stdin.rid);
+ Deno.stdin.isTerminal();
- Deno.isatty(Deno.stdout.rid);
+ Deno.stdout.isTerminal();
- Deno.isatty(Deno.stderr.rid);
+ Deno.stderr.isTerminal();
See the Deno 1.40 blog post for details.
Deno.iter()
Use
iterateReader()
from the Standard Library instead.
+ import { iterateReader } from "jsr:@std/io/iterate-reader";
- for await (const chunk of Deno.iter(reader)) {
+ for await (const chunk of iterateReader(reader)) {
...
}
See deno#9795 for details.
Deno.iterSync()
Use
iterateReaderSync()
from the Standard Library instead.
+ import { iterateReaderSync } from "jsr:@std/io/iterate-reader";
- for (const chunk of Deno.iterSync(reader)) {
+ for (const chunk of iterateReaderSync(reader)) {
...
}
See deno#9795 for details.