From acd01eb2b41e37a480943f79cfa28fc220c4baca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 5 Sep 2024 07:25:56 +0100 Subject: feat: Add a hint on error about 'Relative import path ... not prefixed with ...' (#25430) Running a file like: ``` import "@std/dotenv/load"; ``` Without a mapping in `imports` field of `deno.json` or `dependencies` of `package.json` will now error out with a hint: ``` error: Relative import path "@std/dotenv/load" not prefixed with / or ./ or ../ hint: Try running `deno add @std/dotenv/load` at [WILDCARD]bare_specifier_without_import/main.ts:1:8 ``` Closes https://github.com/denoland/deno/issues/24699 --------- Co-authored-by: David Sherret --- tests/specs/cache/with_bare_import/095_cache_with_bare_import.ts.out | 1 + tests/specs/check/with_bare_import/095_cache_with_bare_import.ts.out | 1 + tests/specs/run/bare_specifier_without_import/__test__.jsonc | 5 +++++ tests/specs/run/bare_specifier_without_import/main.out | 3 +++ tests/specs/run/bare_specifier_without_import/main.ts | 3 +++ 5 files changed, 13 insertions(+) create mode 100644 tests/specs/run/bare_specifier_without_import/__test__.jsonc create mode 100644 tests/specs/run/bare_specifier_without_import/main.out create mode 100644 tests/specs/run/bare_specifier_without_import/main.ts (limited to 'tests/specs') diff --git a/tests/specs/cache/with_bare_import/095_cache_with_bare_import.ts.out b/tests/specs/cache/with_bare_import/095_cache_with_bare_import.ts.out index 2668a6e08..50daf8041 100644 --- a/tests/specs/cache/with_bare_import/095_cache_with_bare_import.ts.out +++ b/tests/specs/cache/with_bare_import/095_cache_with_bare_import.ts.out @@ -1,2 +1,3 @@ [WILDCARD]error: Relative import path "foo" not prefixed with / or ./ or ../ + hint: If you want to use a JSR or npm package, try running `deno add foo` at file:///[WILDCARD]/095_cache_with_bare_import.ts:[WILDCARD] diff --git a/tests/specs/check/with_bare_import/095_cache_with_bare_import.ts.out b/tests/specs/check/with_bare_import/095_cache_with_bare_import.ts.out index 2668a6e08..50daf8041 100644 --- a/tests/specs/check/with_bare_import/095_cache_with_bare_import.ts.out +++ b/tests/specs/check/with_bare_import/095_cache_with_bare_import.ts.out @@ -1,2 +1,3 @@ [WILDCARD]error: Relative import path "foo" not prefixed with / or ./ or ../ + hint: If you want to use a JSR or npm package, try running `deno add foo` at file:///[WILDCARD]/095_cache_with_bare_import.ts:[WILDCARD] diff --git a/tests/specs/run/bare_specifier_without_import/__test__.jsonc b/tests/specs/run/bare_specifier_without_import/__test__.jsonc new file mode 100644 index 000000000..7b5c5e1b6 --- /dev/null +++ b/tests/specs/run/bare_specifier_without_import/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run main.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/run/bare_specifier_without_import/main.out b/tests/specs/run/bare_specifier_without_import/main.out new file mode 100644 index 000000000..a873f2727 --- /dev/null +++ b/tests/specs/run/bare_specifier_without_import/main.out @@ -0,0 +1,3 @@ +error: Relative import path "@std/dotenv/load" not prefixed with / or ./ or ../ + hint: If you want to use a JSR or npm package, try running `deno add @std/dotenv/load` + at [WILDCARD]bare_specifier_without_import/main.ts:1:8 diff --git a/tests/specs/run/bare_specifier_without_import/main.ts b/tests/specs/run/bare_specifier_without_import/main.ts new file mode 100644 index 000000000..67e57b26b --- /dev/null +++ b/tests/specs/run/bare_specifier_without_import/main.ts @@ -0,0 +1,3 @@ +import "@std/dotenv/load"; + +console.log(Deno.env.get("GREETING")); // hello world -- cgit v1.2.3