繁体   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