app静态转换为动态错误.哨兵nextjs



尝试在Kubernetes pod上编译Next.js前端时遇到500错误。我使用以下命令:

npm i --force
npm run build
npm run start

这是错误:

Page changed from static to dynamic at runtime /story/0d3778b0-9e86-4b0a-a043-ed892f2417a0, reason: headers                                                                                              see more here https://nextjs.org/docs/messages/app-static-to-dynamic-error                                                                                                                                   at Object.staticGenerationBailout (/app/.next/server/chunks/827.js:26985:21)                                                                                                                            at headers (/app/.next/server/chunks/827.js:26854:39)                                                                                                                                                   at Object.apply (/app/.next/server/chunks/500.js:78:82)                                                                                                                                                  at T (/app/.next/server/chunks/827.js:27630:25)                                                                                                                                                          at Ma (/app/.next/server/chunks/827.js:27793:33)                                                                                                                                                       at Array.toJSON (/app/.next/server/chunks/827.js:27586:32)                                                                                                                                             at stringify (<anonymous>)                                                                                                                                                                             at V (/app/.next/server/chunks/827.js:27885:53)                                                                                                                                                        at AsyncLocalStorage.run (node:async_hooks:341:14)                                                                                                                                                       at Object.start (/app/.next/server/chunks/827.js:27997:32)

我怀疑这个问题可能与我的Sentry配置有关,因为当我不使用Sentry时,前端工作正常。下面是我在page/_error.js文件中的Sentry配置代码:

import * as Sentry from '@sentry/nextjs';从'next/error'中导入NextErrorComponent;

const SENTRY_DSN = process.env。process.env.NEXT_PUBLIC_SENTRY_DSN;const isSentryEnabled = !!SENTRY_DSN;

if (isSentryEnabled) {
Sentry.init({
dsn: SENTRY_DSN,
});
}
const CustomErrorComponent = ({ statusCode, hasGetInitialPropsRun, err }) => {
if (isSentryEnabled) {
Sentry.captureException(err);
if (!hasGetInitialPropsRun && err) {
Sentry.captureException(err);
return <NextErrorComponent statusCode={500} />;
}
// Render the default Next.js error page with the status code
return <NextErrorComponent statusCode={statusCode} />;
}
// Render the default Next.js error page with the status code
return <NextErrorComponent statusCode={statusCode} />;
};
CustomErrorComponent.getInitialProps = async (context) => {
if (isSentryEnabled) {
if (context.err) {
Sentry.captureException(context.err);
}
const { res, err, asPath } = context;
if (res && res.statusCode === 404) {
return { statusCode: 404 };
}
const hasGetInitialPropsRun = Boolean(err);
if (err) {
Sentry.captureException(err);
}
const initialProps = await NextErrorComponent.getInitialProps(context);
return { ...initialProps, hasGetInitialPropsRun, err, asPath };
} else {
const initialProps = await NextErrorComponent.getInitialProps(context);
return { ...initialProps };
}
};
export default CustomErrorComponent;

我将配置更改为默认哨兵nextjs

import * as Sentry from "@sentry/nextjs";
import NextErrorComponent from "next/error";
const CustomErrorComponent = props => {
Sentry.captureException(props.err); // Capture the error in Sentry
return <NextErrorComponent statusCode={props.statusCode} />;
};
CustomErrorComponent.getInitialProps = async contextData => {
Sentry.captureException(contextData.err); // Capture the error in Sentry
return {
statusCode: contextData.res?.statusCode ?? 500,
// Set the following to null to disable "Static Generation" optimization
// for this page
getStaticProps: null,
getStaticPaths: null,
};
};
export default CustomErrorComponent;

,并试图阻止渲染Sentry _error.js文件,当我运行构建过程。

npm run build

我已经尝试更改nextJs的版本

我的一些依赖项是:

- next-auth@4.20.1
- next@13.1.6
- @next/font@13.1.6
- @sentry/nextjs@7.43.0
- @next-auth/sequelize-adapter@1.0.7
- @next-auth/typeorm-legacy-adapter@2.0.1

我认为这是Next.js的问题。看看这个问题,他们声称这个问题已经在v13.1.6-canary.0中修复了。有些人声称,回到3.1.1版本修复了这个问题。尝试升级/降级版本,看看问题是否仍然存在。