Home > database >  typescript not creating dist folder
typescript not creating dist folder

Time:04-13

trying to compose typescript project. here is my project structure.

rootdir
    |
    |-----src
    |      |----server.ts
    |      |----other folders
    |-----node_modules
    |-----tsconfig.json
    |-----package.json

tsconfig.json

{
  "compilerOptions": {
    "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
    "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
    "resolveJsonModule": true,

    "outDir": "./dist" /* Redirect output structure to the directory. */,
    "rootDir": "./src" /* Specify the root directory of input files. Use to 

    /* Strict Type-Checking Options */
    "strict": true /* Enable all strict type-checking options. */,
    "noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,

    "esModuleInterop": true /* Enables emit interoperability between CommonJS 

    /* Advanced Options */
    "skipLibCheck": true /* Skip type checking of declaration files. */,
    "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
  },
  "include": ["./package.json"]
}

/dist folder is not getting created for me when I do npm run build.

 "build": "tsc --build tsconfig.json",

CodePudding user response:

Try this one. I hope it will cover our case.

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "resolveJsonModule": true,
    "outDir": "dist",
    "strict": true,
    "noImplicitAny": false,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"]
}

CodePudding user response:

First: Your build command should be tsc --project tsconfig.json. The command you're currently using is trying to build your tsconfig.json file, instead of the actuall source code.

Second: Your tsconfig isn't actually including any of your source code in the build. Change your include array to "incude": ["./src/**/*.ts"]. Your current include array is telling tsc to build your package.json file, instead of the actuall source code.

  • Related