Ooker
Ooker12mo ago

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 ../
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"
"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
.
├── .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/fresh@1.6.1/",
"preact": "https://esm.sh/preact@10.19.2",
"preact/": "https://esm.sh/preact@10.19.2/",
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.1",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.0",
"tailwindcss": "npm:tailwindcss@3.3.5",
"tailwindcss/": "npm:/tailwindcss@3.3.5/",
"tailwindcss/plugin": "npm:/tailwindcss@3.3.5/plugin.js",
"$std/": "https://deno.land/std@0.208.0/",
"daisyui": "npm:daisyui@4.4.19"
},
...
{
"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/fresh@1.6.1/",
"preact": "https://esm.sh/preact@10.19.2",
"preact/": "https://esm.sh/preact@10.19.2/",
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.1",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.0",
"tailwindcss": "npm:tailwindcss@3.3.5",
"tailwindcss/": "npm:/tailwindcss@3.3.5/",
"tailwindcss/plugin": "npm:/tailwindcss@3.3.5/plugin.js",
"$std/": "https://deno.land/std@0.208.0/",
"daisyui": "npm:daisyui@4.4.19"
},
...
Stack Overflow
Deno - Relative import path "$fresh/dev.ts" not prefixed
I have this TypeScript complaint in my editor for a Deno module. Relative import path "$fresh/dev.ts" not prefixed with / or ./ or ../ There is an import_map.json with this content. { ...
5 Replies
Ooker
OokerOP12mo ago
.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
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
Deno AI Helper
Deno AI Helper12mo ago
Based on the error message you're encountering, it seems that the import map is not being correctly resolved during the deployment process. The error indicates that the import path for $fresh/server.ts is not being recognized as a valid module specifier. The import map in your deno.json file appears to be correctly mapping the $fresh/ specifier to the https://deno.land/x/fresh@1.6.1/ URL. However, the deployment process might not be picking up this import map, or there could be an issue with how the import map is being used in the context of the deployment. Here are a few steps you can take to troubleshoot this issue: 1. Ensure the import map is being used: Make sure that the import map is correctly referenced in your deno.json file and that the deployment process is aware of it. If you're using Deno Deploy, the import map should be automatically picked up from the deno.json file. 2. Check the import map's scope: Verify that the import map's scope includes the files that are using the $fresh/ specifier. Import maps can be scoped to certain directories, and if the scope is not set correctly, it might not apply to all necessary files. 3. Verify the file structure: Ensure that the file structure of your project matches the paths specified in the import map and the deno.json tasks. The error message suggests that there might be a mismatch between the expected file structure and the actual one. 4. Check for typos or errors: Double-check the import map and deno.json file for any typos or errors that might be causing the import map to not be recognized correctly. 5. Test locally: Try running your project locally with the import map to see if the issue is specific to the deployment environment. If it works locally, the problem might
Deno AI Helper
Deno AI Helper12mo ago
be with the deployment setup. 6. Consult the documentation: The documentation on import maps might provide additional insights or steps to follow to ensure that your import map is being used correctly during deployment. If you've gone through these steps and the issue persists, it might be helpful to look for similar issues in the Deno community forums or GitHub issues to see if others have encountered and resolved similar problems. Additionally, you can consider reaching out to the Deno community for further assistance. 🦕
Ooker
OokerOP12mo ago
anyone? if the path contains a space or a non-ASCII character then it yields this error:
Error: The deployment failed: Relative import path "$fresh/server.ts" not prefixed with / or ./ or ../
Error: The deployment failed: Relative import path "$fresh/server.ts" not prefixed with / or ./ or ../
I haven't figured out how to escape those characters.
Ooker
OokerOP12mo ago
GitHub
Error: The deployment failed: Relative import path "$fresh/server.t...
Discussed in denoland/fresh#2246 Originally posted by ooker777 January 13, 2024 When deploying I get this error: Deploying... (100.0%) Error: The deployment failed: Relative import path "$fres...

Did you find this page helpful?