2020-05-13 19:19:29 +02:00
# Standard library
Deno provides a set of standard modules that are audited by the core team and
are guaranteed to work with Deno.
Standard library is available at: https://deno.land/std/
## Versioning and stability
Standard library is not yet stable and therefore it is versioned differently
than Deno. For latest release consult https://deno.land/std/ or
2020-06-18 11:13:56 +01:00
https://deno.land/std/version.ts. The standard library is released each time
Deno is released.
2020-05-13 19:19:29 +02:00
We strongly suggest to always use imports with pinned version of standard
2020-06-18 11:13:56 +01:00
library to avoid unintended changes. For example, rather than linking to the
2021-02-19 15:58:19 +01:00
default branch of code, which may change at any time, potentially causing
2020-06-18 11:13:56 +01:00
compilation errors or unexpected behavior:
```typescript
2021-02-19 15:58:19 +01:00
// import the latest release, this should be avoided
2020-06-18 11:13:56 +01:00
import { copy } from "https://deno.land/std/fs/copy.ts";
```
instead, used a version of the std library which is immutable and will not
change:
```typescript
2020-09-27 03:11:01 -07:00
// imports from v$STD_VERSION of std, never changes
2020-07-31 11:12:20 +02:00
import { copy } from "https://deno.land/std@$STD_VERSION/fs/copy.ts";
2020-06-18 11:13:56 +01:00
```
2020-05-13 19:19:29 +02:00
## Troubleshooting
Some of the modules provided in standard library use unstable Deno APIs.
Trying to run such modules without `--unstable` CLI flag ends up with a lot of
2020-06-18 11:13:56 +01:00
TypeScript errors suggesting that some APIs in the `Deno` namespace do not
exist:
2020-05-13 19:19:29 +02:00
```typescript
// main.ts
2020-07-31 11:12:20 +02:00
import { copy } from "https://deno.land/std@$STD_VERSION/fs/copy.ts";
2020-05-13 19:19:29 +02:00
copy("log.txt", "log-old.txt");
```
```shell
$ deno run --allow-read --allow-write main.ts
Compile file:///dev/deno/main.ts
2020-07-31 11:12:20 +02:00
Download https://deno.land/std@$STD_VERSION/fs/copy.ts
Download https://deno.land/std@$STD_VERSION/fs/ensure_dir.ts
Download https://deno.land/std@$STD_VERSION/fs/_util.ts
2020-09-26 14:56:03 -07:00
error: TS2339 [ERROR]: Property 'utime' does not exist on type 'typeof Deno'. 'Deno.utime' is an unstable API. Did you forget to run with the '--unstable' flag?
2020-05-13 19:19:29 +02:00
await Deno.utime(dest, statInfo.atime, statInfo.mtime);
~~~~~
2020-09-26 14:56:03 -07:00
at https://deno.land/std@$STD_VERSION/fs/copy.ts:92:16
2020-05-13 19:19:29 +02:00
2020-09-26 14:56:03 -07:00
TS2339 [ERROR]: Property 'utimeSync' does not exist on type 'typeof Deno'. 'Deno.utimeSync' is an unstable API. Did you forget to run with the '--unstable' flag?
2020-05-13 19:19:29 +02:00
Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
~~~~~~~~~
2020-09-26 14:56:03 -07:00
at https://deno.land/std@$STD_VERSION/fs/copy.ts:103:10
2020-05-13 19:19:29 +02:00
```
Solution to that problem requires adding `--unstable` flag:
```shell
2020-06-11 09:24:41 +09:00
deno run --allow-read --allow-write --unstable main.ts
2020-05-13 19:19:29 +02:00
```
To make sure that API producing error is unstable check
2020-09-27 03:12:33 -07:00
[`lib.deno.unstable.d.ts` ](https://github.com/denoland/deno/blob/$CLI_VERSION/cli/dts/lib.deno.unstable.d.ts )
2020-05-13 19:19:29 +02:00
declaration.
2020-06-18 11:13:56 +01:00
This problem should be fixed in the near future. Feel free to omit the flag if
the particular modules you depend on compile successfully without it.