ronypatil
ronypatil

Reputation: 163

Typescript/Node: Src folder is not generated while building app

My project folder directory is like this

  + build
  + node_modules
  + server
     + config
     + api
     + database
     + ts-model
     - server.ts
  gitignore
  app.js
  package.json
  tsconfig.ts

My tsconfig.ts file is as follows

{
   "compilerOptions": {
   "module": "none",
   "target": "es2016",
   "outDir": "build",
   "noImplicitAny": true,
   "noImplicitReturns": true,
   "noImplicitThis": true
 },
 "include:": [
 "server/**/*.ts"
 ],
 "exclude": [
 "node_modules"
 ]
}

Issue is whenever i do npm run build, my build folder doesn't maintain folder structure. My build folder should contain build>>server>>foldersInsideServer but it is actually build>>foldersInsideServer

  + build
     + config
     + api
     + database
     + ts-model
     - server.ts

I have seen a behavior that whenever I create another folder called "test" and put empty ts file inside, that time build generates like this

+build
   +server
   +test

But as soon as i delete test folder then it again stops generating server folder but shows folders inside server. How can we solve this issue without creating another folder with empty file

Upvotes: 0

Views: 3078

Answers (1)

Saravana
Saravana

Reputation: 40534

Add "rootDir": "./" to your tsconfig.json.

From the TypeScript wiki:

--outDir specifies the "root" directory of the output. The compiler needs a "root" directory in the source to mirror into the output directory. If --rootDir is not specified, the compiler will compute one; this is based on a common path calculation, which is the longest common prefix of all your input files. Obviously this changes with adding a new file to the compilation that has a shorter path prefix.

To ensure the output does not change with adding new files specify --rootDir on the command-line or in your tsconfig.json

Upvotes: 1

Related Questions