我已经构建了一个 next.js 应用程序。这些页面在开发环境中运行良好,但如果我尝试运行生产构建,则只有 index.js 页面正确加载,所有其他页面都以 404 结尾。
npm run build 输出以下内容:
reating an optimized production build ...
Compiled successfully.
Warning: You have opted-out of Automatic Prerendering due to `getInitialProps` in `pages/_app`.
Read more: https://err.sh/next.js/opt-out-automatic-prerendering
Page Size Files Packages
? ? / 66.8 kB 4 27
? /_app 17.9 kB 0 31
? /_document
? /_error 397 B 0 27
? ? /Products/[specificPage]/Dashboard 404 B 4 27
? ? /Products/Overview 95.1 kB 9 30
? ? /Products/Roadmap …Run Code Online (Sandbox Code Playgroud) 我刚刚升级了包@material-ui/core*(4.4.1 => 4.8.3)* & @material/styles*(4.4.1 = 4.8.2)*
现在使用主题的所有内容都没有应用正确的颜色和边距。
主题包中是否有任何我不知道的重大更改?
我正在使用 Next.js 进行服务器渲染。重要说明:在升级包之前一切正常。降级不是一种选择,因为我需要访问较新版本中发布的组件之一。此外,我不想因此将自己锁定在较低版本上。
编辑:代码清晰
_app.js
<Provider store={store}>
<PersistGate persistor={store.__PERSISTOR} loading={null}>
<ThemeProvider theme={theme}>
<CssBaseline />
<Component {...pageProps} user={this.state.user} />
</ThemeProvider>
</PersistGate>
</Provider>
Run Code Online (Sandbox Code Playgroud)
_document.js
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: App => props => sheets.collect(<App {...props} />)
});
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
// Styles fragment is rendered after the app and page rendering finish.
styles: [
<React.Fragment key="styles">
{initialProps.styles}
{sheets.getStyleElement()}
</React.Fragment>
]
};
Run Code Online (Sandbox Code Playgroud)
这一切都非常类似于 Material-UI 提供的示例。我没有看到他们的 git repo …