请求worker-javascript.js时,Next.js getServerSIdeProps出错
我有一个页面,在该页面内有动态导入: http://localhost:3000/rulesets/1请求worker-javascript.js时,Next.js getServerSIdeProps出错,next.js,Next.js,我有一个页面,在该页面内有动态导入: http://localhost:3000/rulesets/1 import dynamic from "next/dynamic"; const RegexInput = dynamic(import("./ExpressionEditor"), { ssr: false, }); export default RegexInput; RequireNumber参数方法: export function
import dynamic from "next/dynamic";
const RegexInput = dynamic(import("./ExpressionEditor"), {
ssr: false,
});
export default RegexInput;
RequireNumber参数方法:
export function requireNumberParam<P extends ParsedUrlQuery>(
context: GetServerSidePropsContext<P>,
name: keyof P
): number {
const str = context.params?.[name];
if (Array.isArray(str)) {
throw new Error(`Param ${name} is an array; expected single item`);
}
const num = str ? parseInt(str as string, 10) : NaN;
if (isNaN(num)) {
throw new Error(`Param ${name} is not a number`);
}
return num;
}
导出函数requireNumberParam(
上下文:GetServerSidePropsContext
,
姓名:keyp
):号码{
const str=context.params?[name];
if(Array.isArray(str)){
抛出新错误(`Param${name}是一个数组;应为单个项`);
}
const num=str?parseInt(str作为字符串,10):NaN;
if(isNaN(num)){
抛出新错误(`Param${name}不是数字`);
}
返回num;
}
在此页面中,有一个对此url的请求:
http://localhost:3000/rulesets/worker-javascript.js
这就是答案
...
<script id="__NEXT_DATA__" type="application/json">
{
"props": {
"pageProps": {},
"__N_SSP": true
},
"page": "/rulesets/[id]",
"query": {
"id": "worker-javascript.js"
},
"buildId": "development",
"isFallback": false,
"err": {
"name": "Error",
"message": "Param id is not a number",
"stack": "Error: Param id is not a number"
},
"gssp": true
}
</script>
...
。。。
{
“道具”:{
“pageProps”:{},
“\u N\u SSP”:正确
},
“页面”:“/rulesets/[id]”,
“查询”:{
“id”:“worker javascript.js”
},
“buildId”:“开发”,
“isFallback”:错误,
“错误”:{
“名称”:“错误”,
“消息”:“参数id不是数字”,
“堆栈”:“错误:参数id不是数字”
},
“gssp”:正确
}
...
它正在控制台上导致错误
检测到worker-javascript.js为参数,
我该怎么解决这个问题
...
<script id="__NEXT_DATA__" type="application/json">
{
"props": {
"pageProps": {},
"__N_SSP": true
},
"page": "/rulesets/[id]",
"query": {
"id": "worker-javascript.js"
},
"buildId": "development",
"isFallback": false,
"err": {
"name": "Error",
"message": "Param id is not a number",
"stack": "Error: Param id is not a number"
},
"gssp": true
}
</script>
...