Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
m0rphed opened this issue Aug 10, 2024 · 4 comments · May be fixed by #326

Comments

@m0rphed
Copy link

m0rphed commented Aug 10, 2024

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

@magurotuna
Copy link
Member

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"
  }
}

@m0rphed
Copy link
Author

m0rphed commented Aug 10, 2024

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 😓

@magurotuna
Copy link
Member

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants