Search code examples
relative-pathfreshjsdeno-deploy

Error: The deployment failed: Relative import path "$fresh/server.ts" not prefixed with / or ./ or ../


When deploying I get this error:

Deploying... (100.0%)
Error: The deployment failed: Relative import path "$fresh/server.ts" not prefixed with / or ./ or ../

A person who had the same error on their machine solves this by adding this to the import map:

  "deno.importMap": "./import_map.json"

This doesn't work on my case. In my understanding this shouldn't be an issue at all. Do you know why is that?

Background

My fresh project is under some sub-folder from the root. The structure is like this:

├── .github
├── .git
└── deno.json/
    └── 1/
        └── Web/
            ├── main.ts
            └── dev.ts

deno.json

{
  "lock": false,
  "tasks": {
    "check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
    "cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -",
    "manifest": "deno task cli manifest $(pwd)",
    "start": "deno run -A --watch=static/,routes/ './1/Web/dev.ts'",
    "build": "deno run -A './1/Web/dev.ts' build",
    "preview": "deno run -A ./1/Web/main.ts",
    "update": "deno run -A -r https://fresh.deno.dev/update ."
  },
...
  "exclude": [
    "**/_fresh/*"
  ],
  "imports": {
    "$fresh/": "https://deno.land/x/[email protected]/",
    "preact": "https://esm.sh/[email protected]",
    "preact/": "https://esm.sh/[email protected]/",
    "@preact/signals": "https://esm.sh/*@preact/[email protected]",
    "@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
    "tailwindcss": "npm:[email protected]",
    "tailwindcss/": "npm:/[email protected]/",
    "tailwindcss/plugin": "npm:/[email protected]/plugin.js",
    "$std/": "https://deno.land/[email protected]/",
    "daisyui": "npm:[email protected]"
  },
...

.github/workflows/deploy.yaml

name: Deploy
on:
  push:
    branches: [main]
  pull_request:
    branches: main

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest

    permissions:
      id-token: write # Needed for auth with Deno Deploy
      contents: read # Needed to clone the repository

    steps:
      - name: Clone repository
        uses: actions/checkout@v3

      - name: Install Deno
        uses: denoland/setup-deno@v1
        with:
          deno-version: v1.x

      - name: Build step
        run: "deno task build" # 📝 Update the build command(s) if necessary

      - name: Upload to Deno Deploy
        uses: denoland/deployctl@v1
        with:
          project: "tranky" # 📝 Update the deploy project name if necessary
          entrypoint: "./1/Web/main.ts" # 📝 Update the entrypoint if necessary

(Also asked on Fresh's GitHub)


Solution

  • Make sure that the path to your main.ts or dev.ts doesn't have space or non-ASCII characters. I haven't figured out how to escape them.