# 模块与 Import Maps

Deno-first 代码使用标准 ESM，本地导入写真实扩展名：

```ts
import { add } from "./math.ts";
import { join } from "jsr:@std/path";
import React from "npm:react";
```

项目中不要在每个文件散落版本号。用 `deno add` 写入 `deno.json` 的 `imports`：

```bash
deno add jsr:@std/path npm:react
```

```json
{
  "imports": {
    "@std/path": "jsr:@std/path@^1.1.2",
    "react": "npm:react@^19.2.0",
    "@/": "./src/"
  }
}
```

然后使用稳定别名：

```ts
import { join } from "@std/path";
import { loadConfig } from "@/config.ts";
```

## 选择顺序

1. Web 标准或 Deno 内置 API；
2. JSR 上的 TypeScript-first 包，尤其 `@std/*`；
3. npm 包，用 `npm:` 或 `deno add` 管理；
4. 仅在确有需要时直接使用 HTTPS import，并锁定来源。

计算得到的动态导入不属于静态模块图：加载本地路径需要 `--allow-read`，加载远程 URL 需要 `--allow-import`。这与普通静态 import 不同。

官方参考：[Modules](https://docs.deno.com/runtime/fundamentals/modules/)、[Import maps example](https://docs.deno.com/examples/import_maps_tutorial/)。
