簡體   English   中英

無法在 AWS EC2 實例上運行基於 NextJS 的節點服務器

[英]Unable to run NextJS based node server on AWS EC2 instance

我曾多次嘗試運行我的節點服務器,但出現此錯誤,為此我嘗試刪除.next 文件夾並在構建完成后再次構建它會引發相同的錯誤。 它在我的本地機器上完美運行。

`Could not find a valid build in the '${this.distDir}' directory! Try building your app with 'next build' before starting the server

Error: Could not find a valid build in the '/root/only4laughproject/.next' directory! Try building your app with 'next build' before starting the server.
at Server.readBuildId (/root/only4laughproject/node_modules/next-server/dist/server/next-server.js:435:23)
at new Server (/root/only4laughproject/node_modules/next-server/dist/server/next-server.js:44:29)
at module.exports (/root/only4laughproject/node_modules/next-server/index.js:4:10)
at module.exports (/root/only4laughproject/node_modules/next/dist/server/next.js:2:161)
at Object.<anonymous> (/root/only4laughproject/server.js:9:13)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)

這是我的 package.json 腳本

    "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "npm run-script build && cross-env NODE_ENV=production node server.js",
    "go": "cross-env NODE_ENV=production node server.js"
  }

在執行 npm 啟動命令時,它在項目構建完成之前運行下一個構建命令它啟動我的 server.js 這就是發生此問題的原因,我在構建完成后嘗試next build我點擊node server.js 它解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM