如何使用自定义服务器 (Nest.js) 构建生产 Next.js

里奇·佩马纳

当我使用自定义服务器时,我需要有关如何使用 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!

Richie Permana

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.jsonbuild做的scripts

"scripts": {
    "build": "NODE_ENV=production nest build && NODE_ENV=production cd src/client && next build"
    ...
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

是否可以使用Team Services中托管的构建服务器使用不同的Node.js版本构建自定义的Npm构建任务?

具有自定义快递服务器的Next.js重新呈现所有自定义路由

使用Node.js在json服务器中自定义路由

nuxt js在本地构建,并在生产服务器上运行

使用Express服务器将多个参数传递给Next.js自定义URL

如何构建next.js生产?

如何正确使用Nest.js的@Headers?

如何在不使用自定义服务器的情况下在Next.js中设置自定义HTTP响应标头?

如何运行Next Js应用程序的构建(输出)目录?

Next js生产版本是否需要服务器中的node_modules文件夹?

Next.js 10 +子路由,如何在服务器端的自定义应用中访问区域设置

使用Next.js自定义布尔玛

Leaflet.js-使用自定义地图服务器

使用 node js 创建简单的服务器(自定义协议)

Aurelia 和 System.js 生产构建

为 Next.js 的服务器文件设置自定义目录

如何将所有异常记录到 nest.js 中的自定义记录器?

服务器端渲染不适用于生产构建 Next.js

Ext js 7 cmd 生产构建失败

Nest.js 在请求对象中使用自定义值

Next.js 生产 js 包没有缩小

Next.js Express 自定义服务器 { dev: true } 永远加载(空响应)但生产 { dev: false } 有效

如何使用 Next.js 实现邮件服务器?

next.js 应用程序在本地运行良好,但在生产中返回 500 内部服务器错误

Nest JS、Mongoose:将服务注入模型

Next.js 生产失败但开发工作

如何在 Next JS 中导入自定义字体?

Next.js 客户端自定义钩子并防止“与服务器/客户端不匹配”错误

Next.js 和 Nest.js 认证