tsc 没有创建 dist 文件夹

JSK*_*JSK 21 javascript node.js typescript

一切都在标题中,试图将我的 TypeScript 项目编译到 ./bin 文件夹,tsc 命令执行没有错误导致没有创建任何内容,不知道为什么。

我的 tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": false,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "lib": ["es6", "es7", "dom", "esnext"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmit": true,
    "noImplicitAny": false,
    "outDir": "bin",
    "removeComments": true,
    "sourceMap": true,
    "target": "es2017",
    "rootDirs": ["src/", "config/"],
    "typeRoots": ["./node_modules/@types", "./typings"]
  },
  "include": ["src/**/*", "./typings"],
  "exclude": ["node_modules", "bin", "**/__mocks__*", "**/*.spec.**", "test", "assets"]
}
Run Code Online (Sandbox Code Playgroud)

在我的 package.json 这是我要编译的脚本:

"scripts": {
    "build-ts": "tsc",
    "watch-ts": "tsc -w",
  },
Run Code Online (Sandbox Code Playgroud)

我的项目结构:

rootdir
    |
    |-----src
    |      |----server.ts
    |      |----app.ts
    |-----test
    |-----node_modules
    |-----typings
    |-----config
    |-----tsconfig.json
    |-----package.json
Run Code Online (Sandbox Code Playgroud)

知道我做错了什么吗?

Ian*_*ane 73

TypeScript 可能无法创建文件夹的另一种情况dist是,在 中设置"incremental": true或 时,您删除该文件夹而不删除跟踪增量构建的 。"composite": truecompilerOptionstsconfig.jsondisttsconfig.tsbuildinfo

如果您tsconfig.tsbuildinfo保留并删除或修改dist,编译器将不需要输出任何内容,因为tsconfig.tsbuildinfo它告诉它没有任何工作要做。问题是tsconfig.tsbuildinfo引用旧状态的dist.

假设您的npm run clean命令运行rimraf dist。您还必须将其更新为rimraf tsconfig.tsbuildinfo.

  • 天哪,我是这个问题的原始发布者,2 年的信,我遇到了同样的问题,但这次是复合的,哈哈... (7认同)
  • 就我而言,它是 `"composite": true` 设置,它隐式设置了 `"incremental": true`。 (5认同)
  • 我在使用 rimraf dist && tsc 时通过 tsconfig.tsbuildinfo 获得了它。这救了我! (2认同)

Rem*_*ing 56

noEmit选项会导致 TypeScript 不发出任何文件。您需要在 build-ts 脚本中删除 "noEmit": true 或传递 --noEmit false 。

特别提示:重命名脚本prepacknpm编译打字稿你,当你运行npm packnpm publish