Nest.js部署到now.sh [英] Nest.js deployment to now.sh

查看:263
本文介绍了Nest.js部署到now.sh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将我的演示应用程序部署到 zeit now.sh 。在文档中我发现如何部署Node.js和Express.js应用程序。但我所指的示例是作为参数js文件与服务器初始化,并且默认情况下Nest.js项目具有作为入口点ts文件。整个应用程序用打字稿编写。如果我尝试使用 main.ts 作为入口点,我收到此错误:

I am currently trying to deploy my demo application to zeit now.sh. In documentation I have found how I can deploy Node.js and Express.js application. But example that I am referring expects as parameter js file with server initialization, and by default Nest.js project has as entry point ts file. Whole application is written in typescript. If I try to use main.ts as entry point, I am getting this error:

11/28 08:05 PM (1m)

{ Error: Cannot find module './app.module'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/var/task/user/src/main.ts:26040:18)
    at __webpack_require__ (/var/task/user/src/main.ts:21:30)
    at Module.module.exports.Object.defineProperty.value (/var/task/user/src/main.ts:26050:69)
    at __webpack_require__ (/var/task/user/src/main.ts:21:30)
    at module.exports.Object.setPrototypeOf.__proto__ (/var/task/user/src/main.ts:85:18)
    at Object.<anonymous> (/var/task/user/src/main.ts:88:10) code: 'MODULE_NOT_FOUND' }

11/28 08:05 PM (1m)

Error while initializing entrypoint: { Error: Cannot find module './app.module'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/var/task/user/src/main.ts:26040:18)
    at __webpack_require__ (/var/task/user/src/main.ts:21:30)
    at Module.module.exports.Object.defineProperty.value (/var/task/user/src/main.ts:26050:69)
    at __webpack_require__ (/var/task/user/src/main.ts:21:30)
    at module.exports.Object.setPrototypeOf.__proto__ (/var/task/user/src/main.ts:85:18)
    at Object.<anonymous> (/var/task/user/src/main.ts:88:10) code: 'MODULE_NOT_FOUND' }

是否有任何人有将Nest.js应用程序部署到now.sh的经验?

Is there anybody that have experience with deployment of Nest.js app to now.sh?

推荐答案

部署时应用程序,你应该首先将它转换为javascript(不管现在如何)。

When you deploy your application, you should always transpile it to javascript first (regardless of now).

1)添加文件 now.json 到你的项目根目录:

1) Add the file now.json to your project root directory:

{
  "version": 2,
  "builds": [
    {
      "src": "dist/main.js",
      "use": "@now/node-server"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "dist/main.js"
    }
  ]
}

2)运行 npm run build 将你的项目编译到dist文件夹

2) Run npm run build to compile your project to the dist folder

3)现在运行 ( cli)部署你的项目

3) Run now (the cli) to deploy your project

这篇关于Nest.js部署到now.sh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆