问题
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' }
Is there anybody that have experience with deployment of Nest.js app to now.sh?
回答1:
When you deploy your application, you should always transpile it to javascript first (regardless of now).
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) Run npm run build
to compile your project to the dist folder
3) Run now
(the cli) to deploy your project
来源:https://stackoverflow.com/questions/53526497/nest-js-deployment-to-now-sh