我正在使用 Next.js 版本 8.0.4。
我面临的问题是,当我第一次构建应用程序并启动它时,它在服务器上占用了近 150 Mb 的内存,但随着时间的推移它逐渐增长,并且在短短 3 或 4 天内变得非常大,具体取决于有多少用户访问我的网站。
我搜索了很多关于内存泄漏的信息,但我认为我的代码中没有做过任何可能导致内存泄漏的事情。
我还注意到,每当我刷新页面或第一次加载它时,就会发生这种使用内存的增长,实际上是当页面在服务器端呈现时。每次刷新我都看到内存增加了 1-2 Mb 并且不会被释放
但是当我在客户端并且我路由到客户端的其他页面时,一切都很好。
我不知道是什么原因造成的。如果有人能帮我解决这个问题,我将不胜感激。
https://i.stack.imgur.com/t4VDm.jpg
如果有帮助,这也是我的 next.config.js:
module.exports = withCss({
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: "[local]___[hash:base64:5]",
},
webpack(config, {dev, isServer}) {
if (ANALYZE) {
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerPort: isServer ? 8080 : 4000,
openAnalyzer: true
}))
}
config.plugins.push(new CompressionPlugin({
filename: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
cache: true,
compressionOptions: {level: 1}
}));
config.optimization.minimizer = [new UglifyJsPlugin({
test: /\.js(\?.*)?$/i,
cache: …
Run Code Online (Sandbox Code Playgroud)