網站搜尋

typescript - 升級 Next.js 從 12 到 13 後出現 ECONNREFUSED 錯誤


我已經從 Nextjs 12 升級到 13,但現在每次運行應用程式時,我都會遇到對本地的 ECONNREFUSED,而且端口不斷變化,而且它無法渲染

> [email  dev /run/media/rud31mp/drive2/Codes/typescript/dtpms/dtpms-usrmngr-ui
> next dev -p 3002

- ready started server on 0.0.0.0:3002, url: http://localhost:3002
- info Loaded env from /run/media/rud31mp/drive2/Codes/typescript/dtpms/dtpms-usrmngr-ui/.env.local
- warn Invalid next.config.js options detected: 
- warn     The root value has an unexpected property, externals, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, configOrigin, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, modularizeImports, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, skipMiddlewareUrlNormalize, skipTrailingSlashRedirect, staticPageGenerationTimeout, swcMinify, target, trailingSlash, transpilePackages, typescript, useFileSystemPublicRoutes, webpack).
- warn See more info here: https://nextjs.org/docs/messages/invalid-next-config
- event compiled client and server successfully in 1216 ms (311 modules)
- wait compiling...
- event compiled client and server successfully in 334 ms (311 modules)
- wait compiling /not-found (client and server)...
- event compiled client and server successfully in 694 ms (555 modules)
- warn Fast Refresh had to perform a full reload due to a runtime error.
- error Error: connect ECONNREFUSED 127.0.0.1:33241
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1487:16)
    at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 33241
}
- wait compiling /_error (client and server)...
- event compiled client and server successfully in 385 ms (556 modules)

答案 #1

這可能和節點 > v16 有關。試著降級到 v16。

我知道這個答案並不理想,但這似乎是 webpack 開發環境與啟動環境本身的請求之間的競態條件。

我還在調查這個問題。請留意此問題

答案#2

你有使用 Nextjs 新的 Google 字型功能嗎?我是說從「next/font/google」匯入字型?

我剛剛在使用 npx create-next-app@latest 初始化新的 Next.js 專案時遇到了類似的問題。預設情況下,layout.tsx 使用了這個新功能:

import { Inter } from 'next/font/google'
const inter=Inter({ subsets: ['latin'] })

我把它註解掉了,錯誤就消失了。我猜 Next.js 嘗試訪問 Google 伺服器以獲取字型,但失敗了。