Next.js项目的Go代理如果还在导入next/go/proxy,直接把路径改成nextjs.org/go/proxy,先别急着改静态配置。包含这次改进的canary构建,会在终端和浏览器开发错误面板里直接标出旧导入语句;就算你手头的环境还没这条新提示,也能先用只读命令搜一遍源码,再用原先报错的请求复测。
报错指向配置值时,先查源码里的旧导入
官方提交b235f78(#102837)明确了一个很容易让人走弯路的问题:静态配置本身没写错,但旧版诊断逻辑可能会把报错指向配置值,误导你去反复查配置。本文依据Next.js的canary提交(GitHub 仓库:github.com/vercel/next.js),该提交没有给出对应的稳定版版本号。作为常规排查,哪怕你的本地构建还不会高亮旧导入,也可以先在项目仓库里跑下面这条只读命令定位源码。
# 在Git已跟踪的Go文件中查找旧路径,显示文件名和行号 git grep -n -F -- 'next/go/proxy' '*.go'
搜出结果后点开对应文件,确认命中的是Go的导入语句,而不是注释或测试文本。要是命令没有输出,先别急着排除旧路径:git grep默认只查Git已跟踪的文件,刚新建还没git add的Go文件可以在编辑器里再全局搜一次。确认代理入口确实没有旧导入后,再按实际报错去查配置。
只替换代理入口的导入路径
适用情况是源码里确实搜到了next/go/proxy。找到位置后,只改引号里的导入路径就行;原本有导入别名或分组的保持原样,别为了这条提示顺手去改代理配置。如果原代码是单行导入,改完后的完整语句如下。
// 使用当前受支持的Go代理SDK导入路径 import "nextjs.org/go/proxy"
保存文件后,用项目原本的开发启动方式复测。下面以已经装好依赖、且在package.json里配好dev脚本的npm项目为例;如果开发服务本身还开着,直接用它复测就行。注意,查版本号只能确认当前目录解析到的Next.js版本,不能只凭版本号里带canary就断定它已经包含这次提交。
# 打印当前项目解析到的Next.js版本
node -p "require('next/package.json').version"
# 运行项目已有的开发脚本
npm run dev
接着重新请求之前触发报错的地址。看到旧路径提示不再出现、请求也恢复正常响应,才算复测通过。如果旧路径提示消失了,但接着报出模块解析错误,说明接下来要去检查项目原有的SDK依赖和go.mod配置;这次提交只改了错误诊断,没有改变SDK解析逻辑,也不会自动替项目迁移go.mod。
按复测结果决定下一步
终端日志和浏览器开发错误面板反映的是同一个问题,只是展示入口不同。排查时以源码里是否还留着旧导入、原请求能不能跑通为准,没必要为了看到新版提示专门去换构建版本。
| 看到的现象 | 优先检查 | 下一步 |
|---|---|---|
| 错误直接标出旧导入行 | 定位到的Go文件是否仍引用旧路径 | 替换导入后重试原请求;若仍报同样的错,按提示位置核对另一处引用或实际启动的项目目录 |
| 只看到静态配置报错 | 代理入口是否还留着旧路径 | 查到旧导入就先替换;确认没有旧导入后,再检查报错指向的配置 |
| 旧路径提示消失,但仍报模块解析错误 | 当前SDK依赖和go.mod设置 | 按项目原有的模块迁移方式处理,再复测同一请求 |
为什么现在能标到具体导入行
从源码实现来看,Turbopack会先给出Go声明分析结果,Next.js从中读取入口文件的导入记录,精确匹配next/go/proxy。这样在代理条件读取流程正式解析配置之前,就能把旧路径拦下来,避免先抛出一句让人误以为是配置填错的报错。

在分析入口包时,代码还会把命中导入的起止位置一并传给诊断模块。需要注意的是,提交里的测试辅助代码为这两个位置字段填入了两个零,那只是测试用的占位数据,不能当成真实报错行号。

下面完整保留官方页面摘录中可见的app.rs代码差异,中文注释用来帮你理清检查的先后顺序;这段摘录停在配置分支开头,并不是可以直接打上的补丁。平时跑自己的项目只需改业务代码里的导入路径,不需要动这段框架源码。
@@ -83,8 +83,8 @@ use turbopack_core::{
};
use turbopack_ecmascript::single_file_ecmascript_output::SingleFileEcmascriptOutput;
use turbopack_go::{
- GoBuildOutcome, GoBuildSession, GoDeclarations, GoSessionPool, GoSourceSelection, GoSourceSet,
- GoToolchainOptions, go_declarations, go_package_bundle_from_sources,
// 引入用于读取导入记录的类型
+ GoBuildOutcome, GoBuildSession, GoDeclarations, GoImport, GoSessionPool, GoSourceSelection,
+ GoSourceSet, GoToolchainOptions, go_declarations, go_package_bundle_from_sources,
go_packages_bundle_from_sources, go_packages_root, go_source_failure, go_source_set,
};
use turbopack_resolve::{ecmascript::cjs_resolve, resolve_options_context::ResolveOptionsContext};
@@ -1114,6 +1114,7 @@ pub async fn app_entry_point_to_route(
AppEntrypoint::AppGoRoute { page, path, .. } => {
if !*app_project.project().next_config().go_routes().await? {
GoRouteIssue {
// 这条路由功能开关错误不附带源码位置
+ source: None,
path: path.clone(),
message: rcstr!("route.go requires experimental.goRoutes: true"),
}
@@ -1219,6 +1220,17 @@ fn go_proxy_handler_source(skip_proxy_url_normalize: bool, base_path: &str) -> R
))
}
// 统一旧导入路径的迁移提示
+const LEGACY_GO_SDK_IMPORT_MESSAGE: &str =
+ "Import `next/go/proxy` is no longer supported. Use `nextjs.org/go/proxy` instead.";
+
// 在指定文件的导入记录里查找旧路径
+fn legacy_go_sdk_import<'a>(entry: &'a GoDeclarations, file: &str) -> Option<&'a GoImport> {
+ entry
+ .selected_imports
+ .get(file)?
+ .iter()
+ .find(|import| import.path == "next/go/proxy")
+}
+
/// Adapter routing may skip the proxy entirely. Every native entrypoint must therefore validate
/// the header fields its proxy conditions depend on, before Go can interpret a different value.
/// Keep this separate from code generation so a proxy body edit does not rebuild every route.
@@ -1245,6 +1257,9 @@ async fn go_proxy_condition_keys(
.get_path_to(path)
.context("Go proxy outside module")?;
let entry = go_declarations(sources, vec![RcStr::from(name)], session).await?;
// 在读取静态配置前检查入口文件的旧导入
+if legacy_go_sdk_import(&entry, name).is_some() {
// 找到旧路径就返回迁移提示
+ bail!(LEGACY_GO_SDK_IMPORT_MESSAGE);
+}
let config =
go_entry_config(&entry.functions, &entry.values, true).map_err(anyhow::Error::msg)?;
for matcher in config["matcher"].as_array().into_iter().flatten() {
@@ -1542,6 +1557,7 @@ mod go_package_alias_tests {
struct GoRouteIssue {
path: FileSystemPath,
message: RcStr,
// 允许错误附带源码位置
+ source: Option<IssueSource>,
}
#[async_trait]
@@ -1553,6 +1569,9 @@ impl Issue for GoRouteIssue {
fn severity(&self) -> IssueSeverity {
IssueSeverity::Error
}
// 将已记录的源码位置交给错误展示层
+fn source(&self) -> Option<IssueSource> {
+ self.source
+}
async fn file_path(&self) -> Result<FileSystemPath> {
Ok(self.path.clone())
}
@@ -2045,6 +2064,17 @@ async fn analyze_go_package(
}
// Helpers compile with the entrypoint, but do not declare its handlers or configuration.
let analysis = go_declarations(*sources, vec![RcStr::from(handler_name)], session).await?;
// 从入口文件的分析结果取得命中的旧导入记录
+if let Some(import) = legacy_go_sdk_import(&analysis, handler_name) {
// 返回迁移错误并附上导入语句的起止位置
+ return go_package_failure(
+ *project,
+ path,
+ *sources,
+ session,
+ LEGACY_GO_SDK_IMPORT_MESSAGE.into(),
+ Some((import.start, import.end)),
+ )
+ .await;
+}
// Next.js owns the program entrypoint. It imports the route directory as an ordinary
// package, so that directory cannot be a program itself. Only files Go selects count:
// `//go:build ignore` generators commonly use `package main`.
@@ -2059,7 +2089,7 @@ async fn analyze_go_package(
imports this directory as a package. Rename the package in every .go file in this \
directory, for example to `package {suggestion}`."
);
- return go_package_failure(*project, path, *sources, session, message.into()).await;
// 包命名错误不附带导入语句的位置
+ return go_package_failure(*project, path, *sources, session, message.into(), None).await;
}
let config = if is_proxy
&& !analysis
@@ -2074,7 +2104,8 @@ async fn analyze_go_package(
let config = match config {
说到底,这次新提示的价值就是帮你省掉一次排查正常配置的冤枉路。不管你用的是不是带这条提示的构建,迁移步骤都一样:查到旧导入就换掉路径;复测如果还有别的报错,再顺着新错误往下查,别把诊断提示的改进当成SDK恢复兼容了。