当我使用自定义服务器时,我需要有关如何使用 Next.js 编译/构建项目的帮助。
我实际上使用Nest.js(TypeScript Node.js 框架)作为我的后端并将我的 Next.js 包装在其中(因为 Nest.js 是基于节点的,所以我认为这应该可以工作)并且它确实可以工作。
这是我遵循的教程之一:https ://javascript.plainenglish.io/render-next-js-with-nestjs-did-i-just-made-next-js-better-aa294d8d2c67 。
当我尝试构建生产时,Next.js 给了我这样的错误
So basically, when I use nest build
command, it successfully compiled but only the backend part (which is Nest.js). Whenever I tried to run into localhost
, it would error and said the same thing above.
And the same as the second command (which is I tried to add next build
command), it would show the same error.
I know where is the problem is (they basically need the compiled .next/
folder) but kinda confused how to solve this. Do you have any idea on how I should tell the compiler that the pages/
folder has been moved into src/client/pages
?
[EDIT] Just for your information, this is my folder architecture.
Any kind of ideas would be a really help. Thanks guys!
I just fixed my own issue right after several minutes I post this even I've struggle for like hours!
所以,只是想让你们知道是否有人遇到过同样的问题。不知何故,我的解决方案是因为这个 Next.js CLI 文档,所以感谢它。
我所做的只是简单地将目录首先更改为正确的Next.js文件夹的代码并开始编译它。我是从package.json
build做的scripts
。
"scripts": {
"build": "NODE_ENV=production nest build && NODE_ENV=production cd src/client && next build"
...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句