morphe
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMorphe Deploy
Morphe 部署
Overview
概述
Deploy a Next.js, Bigfish (), or Vite project to
Morphe (runtime , linux-x64-gnu). The runtime always starts
the function with , so every framework packages down to a zip
whose root is a :
@alipay/bigfishcustom.debian11node server.jsserver.js- Next.js → the standalone server () plus its traced
.next/standalone/server.js. Packaging prunes wrong-platform native bindings and repairs pnpm partial packages.node_modules - Bigfish → a static / SPA build (). Packaging generates a zero-dependency static
dist/(Node built-ins only — nothing to install) that serves the build dir with SPA fallback toserver.js.index.html - Vite → two modes. A pure SPA (→
vite build, no server) reuses the same zero-dependency static wrapper as Bigfish. A custom-server app (adist//server.ts, e.g. Express, that servesserver.jsand backend API routes) is esbuild-bundled into a self-containeddist/at the zip root, with the build dir alongside it.server.js
The fragile, deterministic API work (auth, presign, upload, CRC64, ,
deploy) lives in . The build/config judgment steps are done by you.
.morphe.jsonscripts/morphe.pyRun all commands from the project root. Replace
below with this skill's directory (the folder containing this file).
scripts/morphe.pySKILL_DIR将Next.js、Bigfish()或Vite项目部署到Morphe(运行时为,linux-x64-gnu)。运行时始终通过启动服务,因此每个框架都需要打包为根目录包含的压缩包:
@alipay/bigfishcustom.debian11node server.jsserver.js- Next.js → 独立服务器()及其追踪到的
.next/standalone/server.js。打包过程会剔除错误平台的原生绑定,并修复pnpm的部分包问题。node_modules - Bigfish → 静态/SPA构建产物()。打包过程会生成一个零依赖的静态
dist/(仅使用Node内置模块——无需安装任何依赖),用于提供构建目录的服务,并支持SPA路由回退到server.js。index.html - Vite → 两种模式。纯SPA(→
vite build,无服务器)会复用与Bigfish相同的零依赖静态包装器。自定义服务器应用(包含dist//server.ts,例如Express,同时提供server.js静态资源和后端API路由)会通过esbuild打包为自包含的dist/,放在压缩包根目录,构建目录与其同级。server.js
复杂且确定性的API操作(认证、预签名、上传、CRC64校验、管理、部署)都在中实现。构建/配置判断步骤由你完成。
.morphe.jsonscripts/morphe.py从项目根目录运行所有命令。将下方的替换为该技能的目录(包含此文件的文件夹)。
scripts/morphe.pySKILL_DIRWorkflow
工作流程
Execute these steps in order. Stop and report if any step fails.
按顺序执行以下步骤。若任何步骤失败,立即停止并报告。
1. Ensure logged in
1. 确保已登录
bash
python3 SKILL_DIR/scripts/morphe.py check-auth- Exit 0 → already logged in (valid in
accessToken). Continue.~/.morphe/auth.json - Exit 1 → not logged in. Ask the user for their username and password, then:
bash
python3 SKILL_DIR/scripts/morphe.py login --username "USER" --password "PASS"Never echo the password back. On success the token is saved to .
If login fails (e.g. HTTP 401), report the error and stop.
~/.morphe/auth.jsonbash
python3 SKILL_DIR/scripts/morphe.py check-auth- 退出码0 → 已登录(中存在有效的
~/.morphe/auth.json)。继续执行。accessToken - 退出码1 → 未登录。向用户索要用户名和密码,然后执行:
bash
python3 SKILL_DIR/scripts/morphe.py login --username "USER" --password "PASS"切勿回显密码。登录成功后,令牌将保存到。若登录失败(例如HTTP 401),报告错误并停止。
~/.morphe/auth.json2. Detect the framework
2. 检测框架
bash
python3 SKILL_DIR/scripts/morphe.py detect-framework --project-root .Prints , , , or (exit 1). Detection is ordered
(first match wins):
nextjsbigfishviteunknown- bigfish — in
@alipay/bigfishdeps, or apackage.jsonexists (checked first; Bigfish projects also have next-like build scripts and vite-style tooling).config/config.ts - nextjs — in deps, or a
nextexists.next.config.{js,mjs,ts} - vite — in deps, or a
viteexists (checked last; it's the broadest).vite.config.{js,mjs,ts,mts,cjs}
If it prints , tell the user "暂不支持该项目类型(仅支持 Next.js、Bigfish 与 Vite)"
and stop. Otherwise remember the framework — it selects the build and packaging
path below.
unknownbash
python3 SKILL_DIR/scripts/morphe.py detect-framework --project-root .输出、、或(退出码1)。检测顺序为(匹配到第一个即停止):
nextjsbigfishviteunknown- bigfish — 依赖中包含
package.json,或存在@alipay/bigfish(优先检测;Bigfish项目也有类似Next.js的构建脚本和Vite风格的工具链)。config/config.ts - nextjs — 依赖中包含,或存在
next。next.config.{js,mjs,ts} - vite — 依赖中包含,或存在
vite(最后检测;范围最广)。vite.config.{js,mjs,ts,mts,cjs}
若输出,告知用户“暂不支持该项目类型(仅支持 Next.js、Bigfish 与 Vite)”并停止。否则记录检测到的框架——它将决定后续的构建和打包流程。
unknown3. Resolve the function name
3. 确定函数名称
Ask the user what function name to deploy under. Tell them: 如果不知道填什么,
可以留空,会自动生成一个 格式的随机函数名。
user-xxxxxxxx- If already has a
.morphe.json, mention it as the current default and let the user keep it (just press enter) or override.function_name - Persist the choice (empty input → keep existing or generate):
bash
undefined询问用户要部署到哪个函数名称下。告知用户:如果不知道填什么,可以留空,会自动生成一个 格式的随机函数名。
user-xxxxxxxx- 若中已存在
.morphe.json,将其作为当前默认值告知用户,允许用户保留(直接按回车)或覆盖。function_name - 保存用户的选择(空输入 → 保留现有名称或自动生成):
bash
undefineduser provided a name:
用户提供了名称:
python3 SKILL_DIR/scripts/morphe.py set-function-name --name "NAME" --project-root .
python3 SKILL_DIR/scripts/morphe.py set-function-name --name "NAME" --project-root .
user left it blank:
用户留空:
python3 SKILL_DIR/scripts/morphe.py set-function-name --project-root .
The command prints the final function name and writes it to `.morphe.json`.
This name is reused on every redeploy, so the same function is updated.python3 SKILL_DIR/scripts/morphe.py set-function-name --project-root .
该命令会输出最终的函数名称并写入`.morphe.json`。后续重新部署时会复用此名称,从而更新同一个函数。4. Validate & fix the build config
4. 验证并修复构建配置
Steps 4–6 differ by framework. Follow the branch for the framework detected
in step 2.
步骤4–6因框架而异。根据步骤2中检测到的框架执行对应分支。
4a. Next.js
4a. Next.js
The goal: the runtime target () binary of every native dep must be
installed on disk before the build, so Next's tracer can pick it up. The
step (step 6) handles top-level placement, pruning, and
zipping — but it can only ship a binary that the install actually downloaded.
linux-x64-gnumorphe.py packageEdit the config in place to ensure:
-
standalone output —(else there is no
output: "standalone"to zip)..next/standalone/ -
Install the linux binaries on the build host. Native addons ship as per-platform optional deps; a macOS install only fetches the darwin one.
- pnpm () — add
pnpm-workspace.yamlso the linux-x64-gnu binaries are fetched too. This is the single most important fix; with it, the tracer auto-includes the binding and you usually need NOsupportedArchitecturesat all:outputFileTracingIncludesThen re-runyamlsupportedArchitectures: os: [current, linux] cpu: [current, x64] libc: [current, glibc].pnpm install - npm/yarn — install the specific binding(s) for the target, e.g.
.
npm i --no-save @resvg/resvg-js-linux-x64-gnu --force --os=linux --cpu=x64 --libc=glibc
- pnpm (
-
(Optional) trim the bundle further.already prunes every non-linux-x64-gnu native binary, so you do NOT need
morphe.py packagefor those. Only add excludes for project data the server doesn't need at runtime (large fixtures, raw datasets, docs). Keep anything read at runtime viaoutputFileTracingExcludes(fonts, JSON the route reads).process.cwd()
See for details, per-package binding names, and
how to confirm the linux binary is on disk.
references/nextjs-config.md目标:在构建前,确保每个原生依赖的目标运行时()二进制文件已安装到本地磁盘,以便Next.js的追踪器能捕获到它。步骤(步骤6)会处理顶级目录放置、剔除和压缩——但它只能打包安装过程中实际下载的二进制文件。
linux-x64-gnumorphe.py package就地编辑配置以确保:
-
独立模式输出 —(否则没有
output: "standalone"可供压缩)。.next/standalone/ -
在构建主机上安装Linux二进制文件。原生扩展以按平台可选依赖的形式发布;macOS环境下仅会下载darwin版本。
- pnpm(存在) — 添加
pnpm-workspace.yaml,以便同时获取linux-x64-gnu二进制文件。这是最重要的修复;配置后,追踪器会自动包含绑定,通常完全不需要supportedArchitectures:outputFileTracingIncludes然后重新运行yamlsupportedArchitectures: os: [current, linux] cpu: [current, x64] libc: [current, glibc]。pnpm install - npm/yarn — 安装目标平台的特定绑定,例如。
npm i --no-save @resvg/resvg-js-linux-x64-gnu --force --os=linux --cpu=x64 --libc=glibc
- pnpm(存在
-
(可选)进一步精简包体积。已经会剔除所有非linux-x64-gnu的原生二进制文件,因此你不需要为这些文件设置
morphe.py package。仅需排除服务器运行时不需要的项目数据(大型测试用例、原始数据集、文档)。保留所有通过outputFileTracingExcludes在运行时读取的文件(字体、路由读取的JSON文件)。process.cwd()
详情请参考,其中包含各包的绑定名称以及如何确认Linux二进制文件已安装到本地的方法。
references/nextjs-config.md4b. Bigfish
4b. Bigfish
No native-binding work — Bigfish builds a static / SPA bundle and generates a zero-dependency (Node built-ins only). There
is nothing to install for the linux target and no config to patch in the common
case.
morphe.py packageserver.js- Confirm the app builds to a static bundle. A default Bigfish build emits
site(dist/+ hashed JS/CSS), which is what the generated static server serves.index.html(SSR) is not covered by this static wrapper — if the app truly needs server-side rendering at runtime, stop and tell the user the static path won't serve their SSR routes.deployMode: 'render' - If the build output dir is not (Bigfish lets you override it), note the dir name; you'll pass it via
dist/in step 6.--static-dir
无需处理原生绑定——Bigfish构建的是静态/SPA包,会生成一个零依赖的(仅使用Node内置模块)。通常无需为Linux目标安装任何依赖或修改配置。
morphe.py packageserver.js- 确认应用构建为静态包。默认的Bigfish 构建会生成
site(dist/+ 带哈希的JS/CSS),这正是生成的静态服务器所服务的内容。index.html(SSR)不适用此静态包装器——如果应用确实需要运行时服务端渲染,停止并告知用户静态部署方式无法支持其SSR路由。deployMode: 'render' - 若构建输出目录不是(Bigfish允许自定义),记录该目录名称;在步骤6中通过
dist/参数传入。--static-dir
4c. Vite
4c. Vite
Vite has two modes; (step 6) auto-detects which by probing
for a server entry (, also under ).
morphe.py packageserver.{ts,js,mjs,cjs}src/-
Pure SPA (no server entry) — nothing to install or patch, exactly like Bigfish.emits
vite build(dist/+ hashed assets) and the generated zero-dependency staticindex.htmlserves it with SPA fallback. If the output dir isn'tserver.js, note it fordist/in step 6.--static-dir -
Custom-server (a/
server.tsservingserver.jsand API routes) —dist/will esbuild-bundle that entry into a self-containedpackage. Make sure the server:server.js- listens on and binds
process.env.PORT || 3000(the runtime sets0.0.0.0and routes to all interfaces);PORT - reads its static dir from (e.g.
process.cwd()), since the zip ships the build dir alongsidepath.join(process.cwd(), "dist")at the runtime working dir;server.js - keeps any import dev-only.
viteis always externalized from the bundle (it's huge and pulls in nativeviteaddons — esbuild/ lightningcss/fsevents — that can't be bundled and break the build). A production server must not load it. Put any dev-middleware vite usage behind a lazy, non-production branch, e.g.:.nodetsif (process.env.NODE_ENV !== "production") { const { createServer } = await import("vite"); // lazy: never bundled // ... dev middleware }
Runtime secrets (API keys, etc.) belong in the function environment, not in the zip — the build never bundles your..env- If your server needs an extra package kept out of the bundle (e.g. a native
addon esbuild can't inline), pass it via
.nodein step 6 — but then that package must be reachable at runtime (this is an edge case; most pure-JS deps bundle fine).--external NAME
- listens on
Vite有两种模式;(步骤6)会通过探测服务器入口文件(,也包括目录下的文件)自动检测模式。
morphe.py packageserver.{ts,js,mjs,cjs}src/-
纯SPA(无服务器入口) — 无需安装或修改配置,与Bigfish完全相同。生成
vite build(dist/+ 带哈希的资源),生成的零依赖静态index.html会提供服务并支持SPA路由回退。若输出目录不是server.js,记录该目录名称以便在步骤6中传入dist/。--static-dir -
自定义服务器(包含/
server.ts,同时提供server.js静态资源和API路由) —dist/会将入口文件通过esbuild打包为自包含的package。确保服务器:server.js- 监听并绑定
process.env.PORT || 3000(运行时会设置0.0.0.0并路由到所有接口);PORT - 从读取静态目录(例如
process.cwd()),因为压缩包会将构建目录与path.join(process.cwd(), "dist")放在运行时工作目录的同级;server.js - 仅在开发环境导入。
vite会被强制排除在包外(体积庞大且会引入无法打包的原生vite扩展——如esbuild/lightningcss/fsevents——导致构建失败)。生产服务器绝不能加载它。将所有开发中间件的vite使用放在惰性加载的非生产分支中,例如:.nodetsif (process.env.NODE_ENV !== "production") { const { createServer } = await import("vite"); // 惰性加载:不会被打包 // ... 开发中间件逻辑 }
运行时密钥(API密钥等)应放在函数环境变量中,而非压缩包内——构建过程绝不会打包你的文件。.env- 若服务器需要将某个额外包排除在打包外(例如esbuild无法内联的原生扩展),在步骤6中通过
.node参数传入——但该包必须在运行时可访问(这是边缘情况;大多数纯JS依赖都能正常打包)。--external NAME
- 监听
5. Build
5. 构建
bash
npm run build # or: pnpm build / yarn build (Bigfish: also `bigfish build`)Do NOT hand-copy assets or hand-zip — step 6 does all assembly. (Vite: run only
the frontend build here to produce . For a custom-server app you do
not need to bundle the server yourself — runs esbuild for you in
step 6. If your script already esbuilds the server, that's harmless;
re-bundles into the staged zip regardless.)
dist/packagebuildpackagebash
npm run build # 或:pnpm build / yarn build (Bigfish也可执行 `bigfish build`)切勿手动复制资源或手动压缩——步骤6会完成所有组装工作。(Vite:此处仅运行前端构建以生成。对于自定义服务器应用,你不需要自行打包服务器——会在步骤6中通过esbuild为你完成打包。若你的脚本已经包含esbuild打包服务器的逻辑,也不会有问题;会重新打包并放入临时压缩包中。)
dist/packagebuildpackage6. Assemble the minimal deploy zip
6. 组装最小化部署压缩包
bash
python3 SKILL_DIR/scripts/morphe.py package --project-root .package--framework nextjs|bigfish|viteNext.js — assembles into a runnable zip:
.next/standalone- copies and
.next/staticinto the bundle (not traced by the build);public/ - repairs pnpm partial packages — top-level dirs that hold only
node_modules/<pkg>while the real files live inpackage.json(this shadowing is what crashes.pnpmwith e.g. Cannot find modulenode server.js);@swc/helpers/cjs/_interop_require_default.cjs - prunes every native binding that isn't (darwin/musl/arm64 — often 100M+) and symlinks the kept linux bindings to top-level node_modules, where the runtime resolves them with a bare
linux-x64-gnu. Missing this is why SVG-style code paths work but anything hitting the native addon 500s with Cannot find modulerequire("<pkg>-linux-x64-gnu");…-linux-x64-gnu - zips with symlinks preserved () to
zip -yOUTSIDE the standalone dir (so it never nests a previous./code.zip). The runtime preserves symlinks, and pnpm's layout is mostly symlinks intocode.zip, so this roughly halves the zip..pnpm
Bigfish — assembles a static-server zip:
- locates the build output dir (auto-probes ,
dist,buildfor one containingout; override withindex.html);--static-dir DIR - generates a zero-dependency (Node
server.js/http/fsonly) that serves the build dir and falls back topathfor client-side routes;index.html - stages + the build dir and zips so
server.jsis at the zip root with the build dir alongside it. Noserver.js, so the zip is small.node_modules
Vite — two modes, auto-selected by probing for a server entry:
- SPA (no server entry found) — identical to the Bigfish path above: a
generated zero-dependency static + the build dir.
server.js - Custom-server (a entry, auto-probed; force/override with
server.{ts,js,mjs,cjs}) — esbuild-bundles the entry (--server-entry PATH,--bundle --platform=node --format=cjsalways external, plus anyviteyou pass) into a self-contained--external NAME, then stages it with the build dir (auto-probesserver.js/dist/build, overrideout) and zips so--static-diris at the zip root. Deps are inlined, so noserver.jsships.node_modules
It prints the final path, size, and framework, e.g.
or
or .
packaged: …/code.zip (25M)packaged: …/code.zip (0.2M, framework=bigfish)packaged: …/code.zip (0.7M, framework=vite, mode=server, entry=server.ts)bash
python3 SKILL_DIR/scripts/morphe.py package --project-root .package--framework nextjs|bigfish|viteNext.js — 将组装为可运行的压缩包:
.next/standalone- 将和
.next/static复制到包中(这些文件不会被构建过程追踪);public/ - 修复pnpm的部分包问题——顶级目录仅包含
node_modules/<pkg>,而实际文件存放在package.json中(这种阴影结构会导致.pnpm崩溃,例如出现*Cannot find modulenode server.js*错误);@swc/helpers/cjs/_interop_require_default.cjs - 剔除所有非的原生绑定(darwin/musl/arm64版本——通常体积超过100M),并将保留的Linux绑定软链接到顶级node_modules,以便运行时通过
linux-x64-gnu解析。忽略此步骤会导致SVG等代码路径正常工作,但涉及原生扩展的路径会返回500错误,提示Cannot find modulerequire("<pkg>-linux-x64-gnu");…-linux-x64-gnu - 保留软链接进行压缩(),生成
zip -y(位于独立目录外,避免嵌套之前的./code.zip)。运行时会保留软链接,而pnpm的布局主要是指向code.zip的软链接,因此这能将压缩包体积大致减半。.pnpm
Bigfish — 组装静态服务器压缩包:
- 定位构建输出目录(自动探测、
dist、build目录中包含out的那个;可通过index.html参数手动指定);--static-dir DIR - 生成零依赖的(仅使用Node的
server.js/http/fs模块),用于提供构建目录的服务,并支持客户端路由回退到path;index.html - 将和构建目录放入临时目录并压缩,确保
server.js位于压缩包根目录,构建目录与其同级。无需包含server.js,因此压缩包体积很小。node_modules
Vite — 两种模式,通过探测服务器入口文件自动选择:
- SPA(未找到服务器入口) — 与Bigfish流程完全相同:生成零依赖的静态+ 构建目录。
server.js - 自定义服务器(自动探测到入口;可通过
server.{ts,js,mjs,cjs}参数强制指定) — 通过esbuild打包入口文件(参数为--server-entry PATH,--bundle --platform=node --format=cjs始终排除在外,加上你传入的vite参数)为自包含的--external NAME,然后将其与构建目录(自动探测server.js/dist/build;可通过out参数指定)放入临时目录并压缩,确保--static-dir位于压缩包根目录。依赖会被内联,因此无需包含server.js。node_modules
命令会输出最终路径、体积和框架信息,例如或或。
packaged: …/code.zip (25M)packaged: …/code.zip (0.2M, framework=bigfish)packaged: …/code.zip (0.7M, framework=vite, mode=server, entry=server.ts)7–11. Upload, checksum, and deploy
7–11. 上传、校验和部署
A single command does presign → curl PUT upload → CRC64 checksum →
update (writes ; uses the resolved in
step 3, generating one only if somehow still absent) → call :
.morphe.jsonchecksumfunction_name/api/deploybash
python3 SKILL_DIR/scripts/morphe.py deploy --zip code.zip --project-root .On success it prints the deploy result JSON (including , ,
and when available), then deletes the local (it's
already in OSS and is a large throwaway). Pass to retain it for
inspection. On failure the zip is kept so a redeploy can retry. Report the
outcome to the user — give them the if present. If it prints
or an HTTP error, go back to step 1 (the token may have expired)
or report the failure.
actionfunctionNametriggerUrlcode.zip--keep-ziptriggerUrlnot-logged-in单个命令即可完成预签名 → curl PUT上传 → CRC64校验和 → 更新(写入;使用步骤3中确定的,仅当该名称仍不存在时才自动生成) → 调用:
.morphe.jsonchecksumfunction_name/api/deploybash
python3 SKILL_DIR/scripts/morphe.py deploy --zip code.zip --project-root .成功时会输出部署结果JSON(包含、和可用的),然后删除本地的(已上传到OSS,属于大体积临时文件)。若需保留用于检查,可传入参数。失败时会保留压缩包以便重新部署重试。向用户报告结果——若存在,告知用户。若输出或HTTP错误,回到步骤1(令牌可能已过期)或报告失败。
actionfunctionNametriggerUrlcode.zip--keep-ziptriggerUrlnot-logged-inNotes
注意事项
- The Morphe API advertises cookie auth but login returns an ; the script sends it as both a
accessTokencookie and a Bearer header.morphe_session - in
function_nameis generated ONCE and reused on every redeploy so the same function is updated rather than duplicated. Do not hand-edit or regenerate it..morphe.json - All frameworks deploy with the default ,
command="node server.js"— no per-framework deploy flags. The Bigfish / Vite-SPA static server honorsport=3000(defaults to 3000) so it matches; a Vite custom-server must do the same (step 4c).process.env.PORT - (Next.js) Keeping small is mostly automatic via
code.zip(binding pruning + symlink-preserving zip). The remaining large item is usually project data the build traced in (raw datasets, fixtures, generated outputs under a dir a server componentmorphe.py packages). Trim those withreaddirin the Next config — but never exclude files read at runtime viaoutputFileTracingExcludes(fonts, JSON the route parses). (Bigfish zips are just the static build — already small, noprocess.cwd().)node_modules - (Next.js) If a native addon still 500s at runtime with Cannot find module
: the binary wasn't installed on the build host. Fix the install (step 4a:
<pkg>-linux-x64-gnufor pnpm, orsupportedArchitectures), reinstall, rebuild, repackage.npm i --os=linux --cpu=x64 --libc=glibc …warns when an expected linux binding is absent.package - (Bigfish) A blank page or 404 on a client route means the SPA fallback
isn't reaching , or the build dir wasn't
index.html. Confirmdist/exists in the build dir and passindex.htmlif it's not one of--static-dir/dist/build. The generated static server is for static builds; an SSR (out) app needs a real server entry, not this wrapper.deployMode: 'render' - (Vite) esbuild step fails (e.g. No loader is configured for ".node" files or a glob/
packageerror fromrequire.resolve/vite/lightningcss): the server entry importsfsevents(or another native-addon dep) at the top level. Make that import dev-only / lazy (step 4c) so it's externalized, or pass the dep viavite.--external NAME - (Vite) SPA blank page / 404 on a client route — same as Bigfish: confirm
is in the build dir and pass
index.htmlif it isn't--static-dir/dist/build. A custom-server route 500ing usually means a dep was externalized but actually needed at runtime, or the server reads its static dir from a path other thanout— fix per step 4c.process.cwd() - (Vite) A 500 from a backend route at runtime but not locally is often a missing
runtime secret — set API keys etc. in the function environment (they're
never bundled into the zip from your ).
.env - Full API reference: .
references/api.md
- Morphe API支持Cookie认证,但登录会返回;脚本会同时将其作为
accessTokenCookie和Bearer头发送。morphe_session - 中的
.morphe.json仅生成一次,后续重新部署时会复用,从而更新同一个函数而非创建新函数。请勿手动编辑或重新生成。function_name - 所有框架均使用默认的、
command="node server.js"部署——无需针对框架设置部署参数。Bigfish/Vite-SPA的静态服务器会遵循port=3000(默认3000),因此匹配该设置;Vite自定义服务器也必须遵循此设置(步骤4c)。process.env.PORT - (Next.js)缩小体积主要通过
code.zip自动完成(绑定剔除 + 保留软链接压缩)。剩余的大体积内容通常是构建过程中追踪到的项目数据(原始数据集、测试用例、服务器组件morphe.py package读取的目录下的生成文件)。可通过Next.js配置中的readdir剔除这些内容——但绝不能排除通过outputFileTracingExcludes在运行时读取的文件(字体、路由解析的JSON文件)。(Bigfish压缩包仅包含静态构建产物——体积已很小,无process.cwd()。)node_modules - (Next.js)若原生扩展在运行时仍返回500错误,提示Cannot find module :说明二进制文件未安装到构建主机。修复安装过程(步骤4a:pnpm使用
<pkg>-linux-x64-gnu,或npm执行supportedArchitectures),重新安装、构建、打包。当预期的Linux绑定缺失时,npm i --os=linux --cpu=x64 --libc=glibc …会发出警告。package - (Bigfish)客户端路由出现空白页或404:说明SPA回退未指向,或构建目录不是
index.html。确认构建目录中存在dist/,若目录不是index.html/dist/build,传入out参数。生成的静态服务器仅适用于静态构建;SSR(--static-dir)应用需要真实的服务器入口,而非此包装器。deployMode: 'render' - (Vite)的esbuild步骤失败(例如No loader is configured for ".node" files或来自
package/vite/lightningcss的glob/fsevents错误):说明服务器入口文件顶层导入了require.resolve(或其他带原生扩展的依赖)。将该导入改为仅在开发环境使用/惰性加载(步骤4c),使其被排除在包外,或通过vite参数传入该依赖。--external NAME - (Vite)SPA出现空白页/客户端路由404 — 与Bigfish情况相同:确认构建目录中存在,若目录不是
index.html/dist/build,传入out参数。自定义服务器路由返回500错误通常是因为依赖被排除在包外但运行时需要,或服务器从--static-dir以外的路径读取静态目录——按照步骤4c修复。process.cwd() - (Vite)后端路由在运行时返回500但本地正常:通常是缺少运行时密钥——在函数环境变量中设置API密钥等(这些内容绝不会从你的文件打包到压缩包中)。
.env - 完整API参考:。
references/api.md