部署时出现此错误:
Deploying... (100.0%)
Error: The deployment failed: Relative import path "$fresh/server.ts" not prefixed with / or ./ or ../
在机器上遇到相同错误的人通过将其添加到导入映射来解决此问题:
"deno.importMap": "./import_map.json"
这对我的情况不起作用。根据我的理解,这根本不应该是一个问题。你知道这是为什么吗?
我的新项目位于根目录的某个子文件夹下。结构是这样的:
├── .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
没有足够的信息来确定到底是什么导致了此错误。提供使用来自类似或完全相同的 $fresh/server.ts 的导入语句的文件将有很大帮助,因为它可能源自错误导入的函数。