【问题标题】:deploy Typescript GraphQL in production issue在生产问题中部署 Typescript GraphQL
【发布时间】:2020-05-03 23:13:04
【问题描述】:

我已经尝试了一周的时间来研究并将我的服务部署到生产中,但总是无法编译,我的服务器使用 Typescript、Nexus GraphQL、Prisma 和 docker-compose,在开发模式下我可以使用 ts-node-dev 顺利运行之前第一次运行我的应用程序,我需要激活 Prisma 的 docker-compose,然后部署 Prisma 服务和生成的服务,然后我运行 ts-node-dev,它可以工作,但是当我在 ts-node 中进行生产时,它失败了,我也尝试使用pm2,但它不起作用,因为当我使用ts-node时,它总是无法编译我的服务器。

我在 pm2 GitHub running typescript with pm2 上的这个开放问题中尝试了很多事情选项

我也试过这个pm2 start ts-node -- -P tsconfig.server.json ./src 我的 tsconfig.server.json 就像这样

{
  "extends": "./tsconfig",
  "compilerOptions": {
    "sourceMap": false
  }
}

这是我的基础 tsconfig.json :

{
    "compilerOptions": {
         "lib": ["esnext", "dom"],
          "sourceMap": true, 
          "outFile": "./",
          "outDir": "./dist",  
          "strictFunctionTypes": true,
          "strictBindCallApply": true,
          "noImplicitThis": true,                
          "alwaysStrict": true, 
          "skipLibCheck": true,  
          "esModuleInterop": true
    }
}

运行上面提到的命令后编译失败

我已经尝试过使用 PM2 生态系统,它仍然是一样的,没有任何效果 我的生态系统是这样的

{
    "script": "ts-node",
    "args": "./src"
}

你们都使用 Typescript 成功了吗? 我能知道你如何部署它们吗? 如果你分享你的经验,这对我来说意味着:)并希望你能提供帮助:)

【问题讨论】:

    标签: node.js typescript graphql pm2 prisma


    【解决方案1】:

    请尝试使用tsc 转译您的项目。例如。 tsc --outDir dist/ 在 dist 文件夹中创建有效的 .js 文件。如果在转译过程中出现任何错误,您需要修复它们。

    成功转译后,您可以使用 node 从 dist 文件夹中提供您的有效 js。例如。 node dist/src/index.js.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 1970-01-01
      • 2020-01-09
      相关资源
      最近更新 更多