Nest JS构建不会生成dist文件夹

use*_*181 8 node.js nestjs

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

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

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/*"]
  }
}
Run Code Online (Sandbox Code Playgroud)

包.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"
  }
Run Code Online (Sandbox Code Playgroud)

当我执行时npm run build什么也没有发生。没有错误。没有 dist 文件夹。任何人都可以帮我解决这个问题吗?

mic*_*ael 21

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

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

或者简单地关闭tsconfig.json 中的incremental和选项:noEmit

"noEmit": false       // <- remove this or set to false
"incremental": false, // <- remove this or set to false
Run Code Online (Sandbox Code Playgroud)


use*_*181 1

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

"typescript": "3.7.2",
Run Code Online (Sandbox Code Playgroud)