[英]Unable to run NextJS based node server on AWS EC2 instance
I have tried to run my node server multiple times I am getting this error, for this I tried to delete.next folder and build again after build complete it throws same error.我曾多次尝试运行我的节点服务器,但出现此错误,为此我尝试删除.next 文件夹并在构建完成后再次构建它会引发相同的错误。 It is running perfectly on my local machine.它在我的本地机器上完美运行。
`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)
here is my package.json script这是我的 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"
}
on doing npm start command it is running next build command before project build finish it starts my server.js that's why this problem occur, I tried next build
after build complete I hit node server.js
.在执行 npm 启动命令时,它在项目构建完成之前运行下一个构建命令它启动我的 server.js 这就是发生此问题的原因,我在构建完成后尝试next build
我点击node server.js
。 It resolve my issue.它解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.