deployctl icon indicating copy to clipboard operation
deployctl copied to clipboard

The deployment failed: Relative import path, but import path was specified in deno.json imports section

Open m0rphed opened this issue 1 year ago • 4 comments

Hi!

I am having troubles deploying Hono project (deployctl 1.12.0):

❯ deployctl deploy --env-file=./.env --project=currency-exchange-rates 
i Using config file 'C:\Users\morph\proj\pet-react-hono-currency\display-currency-widget\server\deno.json'                                                                                                                                            
√ Deploying to project currency-exchange-rates.
√ Entrypoint: C:\Users\morph\proj\pet-react-hono-currency\display-currency-widget\server\main.ts                                                                                                                                                      
i Uploading all files from the current dir (C:\Users\morph\proj\pet-react-hono-currency\display-currency-widget\server)                                                                                                                               
√ Found 5 assets.
√ Uploaded 1 new asset.
× Deployment failed.
error: The deployment failed: Relative import path "hono/cors" not prefixed with / or ./ or ../

maybe Deno Deploy does not fully read "imports" section inside my deno.json (?):

{
  "imports": {
    "hono": "jsr:@hono/hono@^4.5.2",
    "@std/dotenv/load": "jsr:@std/dotenv/load"
  },
  "tasks": {
    "start": "deno run --allow-net --allow-read --allow-env main.ts"
  },
  "compilerOptions": {
    "jsx": "precompile",
    "jsxImportSource": "hono/jsx"
  },
  "deploy": {
    "exclude": [".env"],
    "include": ["./jsons", "*.ts"],
    "entrypoint": "./main.ts"
  }
}

main.ts:

import { Hono } from "hono";
import { serveStatic } from "hono/deno";
import { cache } from "hono/cache";
import { cors } from "hono/cors";
import "@std/dotenv/load"
import { parseKnownCurrencies } from "./processData.ts";
import { CurrencyApiResponse } from "./types.ts";
...

I am getting:

× Deployment failed.
error: The deployment failed: Relative import path "@std/dotenv/load" not prefixed with / or ./ or ../

Which is strange for me - because locally with deno task start it all runs just fine on Deno version: 🦕 v1.45.4+8bab761

  • then is tried this:
import { Hono } from "hono";
import { serveStatic } from "hono/deno";
import { cache } from "hono/cache";
import { cors } from "hono/cors";
- import "@std/dotenv/load"
+ import "jsr:@std/dotenv/load"
import { parseKnownCurrencies } from "./processData.ts";
import { CurrencyApiResponse } from "./types.ts";
  • and now I am getting:
error: The deployment failed: Relative import path "hono/cors" not prefixed with / or ./ or ../

but hono is definitely in my imports

looks similar to #139

m0rphed avatar Aug 10 '24 17:08 m0rphed

Hi @m0rphed, thanks for the issue report with detailed information. I think the reason your config isn't loaded correctly is because you don't specify deno.json in your include property. deployctl respects your config and decides to not upload your deno.json to the build pipeline where dependency resolution happens using import maps declared in deno.json if present.

So can you try again with the following change?

{
  "imports": {
    "hono": "jsr:@hono/hono@^4.5.2",
    "@std/dotenv/load": "jsr:@std/dotenv/load"
  },
  "tasks": {
    "start": "deno run --allow-net --allow-read --allow-env main.ts"
  },
  "compilerOptions": {
    "jsx": "precompile",
    "jsxImportSource": "hono/jsx"
  },
  "deploy": {
    "exclude": [".env"],
-    "include": ["./jsons", "*.ts"],
+    "include": ["./jsons", "*.ts", "deno.json"],
    "entrypoint": "./main.ts"
  }
}

magurotuna avatar Aug 10 '24 17:08 magurotuna

Yes, thank you! I included deno.json - "include": ["./jsons", "*.ts", "deno.json"], and it now works, and all dependencies were imported successfully.

It was very unclear to me, that I needed to explicitly include deno.json, maybe I misread the docs 😓

m0rphed avatar Aug 10 '24 21:08 m0rphed

Glad your second attempt succeeded!

It was very unclear to me, that I needed to explicitly include deno.json, maybe I misread the docs 😓

I totally agree. I think what makes users particularly confused is this message line:

i Using config file 'C:\Users\morph\proj\pet-react-hono-currency\display-currency-widget\server\deno.json'

This is likely giving users wrong idea that import maps in deno.json will be used in module resolution, although it's not the case. We definitely would like to improve or add messages to tell users that no import maps are found if they either explicitly specify deno.json in the exclude field, or don't include deno.json in the include field.

magurotuna avatar Aug 11 '24 05:08 magurotuna

JFYI I've created a patch to improve messages when the import map is not included possibly against user's expectation. #326

magurotuna avatar Aug 11 '24 09:08 magurotuna