Nest JS构建未生成dist文件夹。

8

我已经使用 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/*"]
  }
}

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 文件夹。请问有谁能帮我解决这个问题吗?


1
你有任何 tsconfig.buildinfo 文件吗?如果有的话,请尝试删除它们。有时这些文件会导致增量构建无法重新生成 dist 目录。 - Jay McDoniel
@JayMcDoniel 不,我没有tsconfig.buildinfo文件。 - user1688181
1
尝试将构建脚本更改为“nest build”。 - Derryl Thomas
2个回答

21

我遇到了相同的问题,问题在于如果存在一些 .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

我使用的是 typescript: ^4.7.4, nest: 9 - Thach Lockevn
解决了同样的问题给我 - Gabriel Silva

1

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

"typescript": "3.7.2",

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接