【问题标题】:How solve experimentalDecorators warning using typescript and PM2?如何使用 typescript 和 PM2 解决实验性装饰器警告?
【发布时间】:2021-11-01 08:07:52
【问题描述】:

我正在开发一个使用 node.js 和 typescript 的项目。如果我运行 TSC 或命令来构建项目,它可以工作,因为我的 tsconfig.json 中有 "experimentalDecorators": true 选项。

但是,当我使用具有相同配置的 pm2 将它放入我的开发服务器时,使用 exosystem.config.json 和不使用它都不起作用。

首先,我有这个 tsconfig.json:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
    "skipLibCheck": true,
    "sourceMap": true,
    "outDir": "./dist",
    "moduleResolution": "node",
    "removeComments": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "rootDir": "src",
    "composite": true,
    "declaration": true,
    "noEmitOnError": false,
    "preserveConstEnums": true,
  },
  "exclude": ["node_modules"],
  "include": ["src"],
}

我的项目结构是:

  • index.ts
  • tsconfig.json
  • src/
  • ecosystem.config.js

我的生态系统.config.js 是:

module.exports = {
  apps : [{
    name: "app",
    script: './index.ts',
    autorestart: true,
    exec_mode: "fork",
    watch: true,
    env: {
      NODE_ENV: 'development',
    },
    env_production: {
      NODE_ENV: 'production',
    },
  }
],
};


如果我调试 pm2 日志,我会遇到此错误:

Error

【问题讨论】:

    标签: node.js typescript pm2 tsconfig tsc


    【解决方案1】:

    我用这个生态系统.config.js 配置解决了这个错误:

    module.exports = {
      apps : [{
        name: 'app',
        script: './node_modules/.bin/ts-node',
        args: '-P ./tsconfig.json ./index.ts',
        watch: true,
        restart_delay: 10000,
        wait_ready: true
      }],
    
    };
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2016-11-11
    • 2018-04-05
    • 2018-11-19
    • 2017-05-25
    • 2017-02-08
    • 2018-03-31
    • 2015-10-22
    • 2020-11-08
    • 2019-08-25
    相关资源
    最近更新 更多