vite-plugin: SSR function import path is wrong when Vite root is a subdirectory (relative build.outDir resolved against cwd)
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript, vite
- 領域
- build-system
調査の方向性
build.outDir 環境を使用する writeBundle ロジックの周辺にある dist/main.js から始め、次にリポジトリのルートから pnpm run build を実行して、報告された再現手順を確認します。完了条件は、web/.netlify/v1/functions/server.mjs が正しい相対インポートを使用し、Netlify Functions のバンドリングがサブディレクトリの Vite root に対して server.js を解決することです。
索引モデルが issue の本文から書いたものです。
説明
Environment
@netlify/vite-plugin-tanstack-start1.3.19 (bundles@netlify/vite-plugin3.0.1)@tanstack/react-start1.168.54vite8.3.0- Node 24, pnpm
Summary
When the Vite root is a subdirectory of the repository and the build runs from the repository root, the generated SSR function gets an extra ../ in its import specifier.
# web/.netlify/v1/functions/server.mjs (generated)
import serverEntrypoint from "../../../../dist/server/server.js";
# expected
import serverEntrypoint from "../../../dist/server/server.js";
Netlify's Functions bundling then fails:
◈ Functions bundling
◈ Packaging Functions from web/.netlify/v1/functions directory:
- server.mjs
X [ERROR] Could not resolve "../../../../dist/server/server.js"
web/.netlify/v1/functions/server.mjs:1:29
This makes the SSR/API function undeployable for this layout. The same wrong specifier is produced regardless of whether the directory is discovered as a framework function (<base>/<package>/.netlify/v1/functions) or via [functions] directory.
How to reproduce
Repo layout where Vite root is a subdirectory but the build is invoked from the repo root:
repo/
├─ netlify.toml # [build] command = "pnpm run build"
├─ package.json # "build": "vite build --config web/vite.config.ts"
└─ web/
├─ vite.config.ts # root: <web/>
└─ src/...
web/vite.config.ts:
export default defineConfig({
root: rootDir, // web/
plugins: [tanstackStart(), netlify(), react()],
});
Then:
pnpm run build # from repo root, process.cwd() !== config.root
cat web/.netlify/v1/functions/server.mjs
Cause
@netlify/vite-plugin dist/main.js (build plugin):
async writeBundle(_, bundle) {
const functionsDirectory = join(resolvedConfig.root, NETLIFY_FUNCTIONS_DIR);
const serverEntrypoint = getServerEntrypoint(bundle, this.environment.config.build.outDir);
const serverEntrypointRelativePath = toPosixPath(relative(functionsDirectory, serverEntrypoint));
// ...
}
this.environment.config.build.outDir is a relative value here (dist/server): TanStack Start's plugin derives the per-environment output directory as join(userConfig.build?.outDir ?? 'dist', 'server') (@tanstack/start-plugin-core vite/output-directory.ts), so the environment config keeps it relative.
path.relative(from, to) resolves a relative to against process.cwd(). When process.cwd() !== config.root, the entry path resolves to <repo>/dist/server/server.js instead of <repo>/web/dist/server/server.js, producing one extra ../.
In a project where cwd === root this happens to work, which is why it only shows up with a subdirectory root.
Suggested fix
Resolve the output directory against the Vite root before computing the relative path:
const outDir = isAbsolute(this.environment.config.build.outDir)
? this.environment.config.build.outDir
: resolve(resolvedConfig.root, this.environment.config.build.outDir);
const serverEntrypoint = getServerEntrypoint(bundle, outDir);
Workaround
Setting an absolute build.outDir in vite.config.ts avoids the issue:
build: { outDir: path.join(rootDir, "dist") }
but it would be good not to require that.
- 主要言語
- TypeScript
- スター
- 1
- フォーク
- 4
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
netlify/framework-adapters のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
netlify/framework-adapters#67 · コメント 3 件 · リアクション 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
-
`@netlify/vite-plugin` fails to load under `TypeScript 7` via `ts-api-utils` `TypeFlags` accessオープン
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
netlify/framework-adapters#65 · コメント 1 件 ·
-
framework-bump-failure
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
netlify/framework-adapters の issue をすべて見る
似ている issue
-
level/task type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
wazuh/wazuh-dashboard-plugins#9508 ·
メンテナーはふだん 1 日以内に返信
-
Testnet EOL page links Zonescan mainnet対応中かも @napelvs が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Azure-Samples/azure-search-openai-demo#3249 ·
メンテナーはふだん 1 日以内に返信
-
[Docs] docs/architecture.mermaid leaves out 21 of the 51 src/ directories対応中かも @uyg7x が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
enhancement status:needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
dongdongbh/Mindwtr#1438 ·
メンテナーはふだん 1 日以内に返信