Search code examples
javascriptnode.jstypescript

tsc not creating the dist folder


All is in the title, trying to compile my TypeScript project to ./bin folder, the tsc commend execute without error resulting in nothing created, can't figure out why.

my 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"]
}

In my package.json this is my scripts to compile:

"scripts": {
    "build-ts": "tsc",
    "watch-ts": "tsc -w",
  },

the structure of my project:

rootdir
    |
    |-----src
    |      |----server.ts
    |      |----app.ts
    |-----test
    |-----node_modules
    |-----typings
    |-----config
    |-----tsconfig.json
    |-----package.json

Any idea what I'm doing wrong?


Solution

  • The noEmit option causes TypeScript to not emit any files. You need to either remove "noEmit": true or pass --noEmit false in your build-ts script.

    Bonus tip: Rename the script to prepack to have npm compile the TypeScript for you when you run npm pack or npm publish.