Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 436
JSK Avatar asked Nov 26 '19 16:11

JSK


People also ask

Where does the dist folder come from?

The dist folder, short for distribution folder, is dynamically generated when using the nuxt generate commands and includes the generated production ready HTML files and assets that are necessary to deploy and run your statically generated Nuxt application.

Is dist folder necessary?

The dist folder is for production website it's not necessary to have it. It will contain for example your image, css, script, vendor folder ready for production (minified and concatenated). You can check on google for this.

What is dist TypeScript?

dist — the folder that has the output from the compiler. node_modules — the folder containing the packages that the app and dev tools require. src — the folder containing the source code files that will be compiled by the TypeScript compiler. package.


2 Answers

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.

like image 93
Remco Haszing Avatar answered Nov 04 '22 20:11

Remco Haszing


Another situation where TypeScript might not create a dist folder is when "incremental": true or "composite": true is set in compilerOptions in tsconfig.json, and you delete the dist folder without deleting the tsconfig.tsbuildinfo that keeps track of the incremental builds.

If you keep tsconfig.tsbuildinfo around and delete or modify dist, the compiler won't see a need to output anything, since tsconfig.tsbuildinfo is telling it that there's no work to do. The problem is the tsconfig.tsbuildinfo references an old state of dist.

Say your npm run clean command runs rimraf dist. You'll have to update it to also rimraf tsconfig.tsbuildinfo.

like image 27
Ian MacFarlane Avatar answered Nov 04 '22 19:11

Ian MacFarlane