Version
envinfo@7.21.0
Ok to proceed? (y) y
System:
OS: macOS 26.5.2
CPU: (16) arm64 Apple M4 Max
Memory: 48.68 GB / 128.00 GB
Shell: 5.9 - /bin/zsh
Browsers:
Chrome: 150.0.7871.182
Safari: 26.5.2
npmPackages:
@modern-js/app-tools: 3.7.0 => 3.7.0
@modern-js/plugin-bff: ^3.7.0 => 3.7.0
@modern-js/runtime: 3.7.0 => 3.7.0
@modern-js/server-runtime: ^3.7.0 => 3.7.0
@modern-js/tsconfig: 3.7.0 => 3.7.0
Details
问题描述
按照官网所示步骤,启用BFF,执行dev命令,请求BFF接口,报错:message: "Can't call useContext out of server scope"
期望
程序能够正常运行,返回值正确
BFF函数
// FilePath: myapp/api/lambda/hello.ts
import { useHonoContext } from "@modern-js/server-runtime";
export const get = async () => {
const c = useHonoContext();
console.info(`access url: ${c.req.url}`);
return "hello world";
};
依赖
"name": "myapp",
"version": "0.1.0",
"scripts": {
"dev": "modern dev",
"build": "modern build",
"serve": "modern serve",
"lint": "biome check"
},
"engines": {
"node": ">=20"
},
"dependencies": {
"@modern-js/plugin-bff": "^3.7.0",
"@modern-js/runtime": "3.7.0",
"@modern-js/server-runtime": "^3.7.0",
"react": "^19.2.3",
"react-dom": "^19.2.0"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@modern-js/app-tools": "3.7.0",
"@modern-js/tsconfig": "3.7.0",
"@types/node": "^20",
"@types/react": "^19.1.8",
"@types/react-dom": "^19.1.6",
"typescript": "~5.7.3"
}
}
配置项
import { defineConfig, appTools } from "@modern-js/app-tools";
import { bffPlugin } from "@modern-js/plugin-bff";
export default defineConfig({
plugins: [appTools(), bffPlugin()],
});
Reproduce link
无
Reproduce Steps
- bff中的hello接口使用useHonoContext();
- 执行
pnpm run dev;
- 请求bff中的hello接口;
- 报错:Can't call useContext out of server scope
Version
Details
问题描述
按照官网所示步骤,启用BFF,执行dev命令,请求BFF接口,报错:message: "Can't call useContext out of server scope"
期望
程序能够正常运行,返回值正确
BFF函数
依赖
配置项
Reproduce link
无
Reproduce Steps
pnpm run dev;