【问题标题】:Nest JS build does does not generate the dist folderNest JS 构建不生成 dist 文件夹
【发布时间】:2020-05-08 20:36:36
【问题描述】:

我已经用nest js实现了rest api项目。它在本地环境中运行良好。(pm start)

我想构建并部署它。但是 build 命令不会生成灰尘文件夹。以下是我的配置

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "allowJs": true,
    "checkJs": true, 
    "noEmit": true
  },
  "exclude": ["node_modules"],
  "paths": {
    "@app/*": ["src/*"],
    "@test/*": ["test/*"]
  }
}

package.json

 "scripts": {
    "build": "tsc -p tsconfig.build.json",
    "format": "prettier --write \"src/**/*.ts\"",
    "start": "npm run start:prod",
    "start:dev": "concurrently --handle-input \"wait-on dist/main.js && nodemon\" \"tsc -w -p tsconfig.build.json\" ",
    "start:prod": "node dist/src/main.js",
    "lint": "tslint -p tsconfig.json -c tslint.json",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json",
    "gcp-build": "npm run build"
  }

当我执行npm run build 时,什么也没有发生。没有错误。没有 dist 文件夹。 谁能帮我解决这个问题?

【问题讨论】:

  • 您有任何tsconfig.buildinfo 文件吗?如果是这样,请尝试删除这些。有时那些可以使增量构建在重新生成 dist 时遇到问题
  • @JayMcDoniel 不,我没有 tsconfig.buildinfo 文件
  • 尝试将构建脚本更改为 - "nest build"

标签: node.js nestjs


【解决方案1】:

遇到同样的问题,问题是如果有一些.tsbuildinfo 文件(当incremental 选项打开时),TS 编译器不会生成/dist(将JS 编译为TS)。

所以,基本上你需要做的是在构建项目之前删除所有.tsbuildinfo 文件。

或者直接关闭 tsconfig.json 中的 incrementalnoEmit 选项:

"noEmit": false       // <- remove this or set to false
"incremental": false, // <- remove this or set to false

【讨论】:

    【解决方案2】:

    一旦我在 package.json 文件中将 typescript 版本更新为 3.7.2,dist 文件夹就会生成。以前它是 3.4.1

    "typescript": "3.7.2",
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-28
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多