## 事象 [[Deno]]プロジェクトで、Localに存在する別の[[Deno]]プロジェクト (ここでは[[🦉Silhouette Core]]) をimportするため以下のようなコードを書いた。 ```ts import { Repetition } from "file:///home/tadashi-aikawa/git/github.com/tadashi-aikawa/silhouette-core/mod.ts"; if (import.meta.main) { const r = Repetition.from("every week"); console.log(r); } ``` しかし、これはエラーになる。 ```error error: Relative import path "owlelia" not prefixed with / or ./ or ../ and not in import map from "file:///home/tadashi-aikawa/git/github.com/tadashi-aikawa/silhouette-core/domain/vo/Repe tition.ts" at file:///home/tadashi-aikawa/git/github.com/tadashi-aikawa/silhouette-core/domain/vo/Repetition.ts:1:29 ``` ## 原因 `mod.ts`自体の読み込みは成功しているが、[[🦉Silhouette Core]]の依存関係をimportする際に[[🦉Silhouette Core]]で定義された[[Import Maps (Deno)|Import Maps]]を認識しないから。具体的には[[🦉Silhouette Core]]の以下コードで[[🦉Owlelia]]がimportできない。 ```ts import { ValueObject } from "owlelia"; ``` [[🦉Silhouette Core]]の`deno.json`では以下の[[Import Maps (Deno)|Import Maps]]が定義されているが、当然[[🦉Silhouette Core]]を利用するプロジェクトにはこの[[Import Maps (Deno)|Import Maps]]が有効にならないから。 ```json "imports": { "@std/assert": "jsr:@std/assert@1", "owlelia": "npm:owlelia@^0.48.1" } ``` ## 解決方法 `deno run` コマンド実行時に [[--import-map (Deno)|--import-map]] を指定する。たとえば以下のような感じ。 ```console deno run --import-map ~/git/github.com/tadashi-aikawa/silhouette-core/deno.json main.ts ``` これで[[🦉Silhouette Core]]内のimportは正常に動作する。`deno.json`には他にもプロパティが存在するため以下のようなwarningも表示されるが気にしなくてよい。 ```warning Import map diagnostics: - Invalid top-level key "name". Only "imports" and "scopes" can be present. - Invalid top-level key "version". Only "imports" and "scopes" can be present. - Invalid top-level key "exports". Only "imports" and "scopes" can be present. - Invalid top-level key "tasks". Only "imports" and "scopes" can be present. ```